In Integration Testing, does it make sense to replace the Async process with a synchronous one for testing?

In integration tests, asynchronous processes (methods, external services) make very complex test code. If instead I took into account the asynchronous part and created a dependency and replaced it with the synchronous part for testing, would this be “good”?

Replacing an asynchronous process with a synchronous one, I am not testing in the spirit of integration testing? I assume that I assume that integration testing refers to testing that is close to real.

+5
source share
3 answers

Good question.

unit test , , . , - , , , , .

"waitFor", , , - , . , java-specific , JUnitConditionRunner. :

conditionRunner = new JUnitConditionRunner(browser, WAIT_FOR_INTERVAL, WAIT_FOR_TIMEOUT);   

protected void waitForText(String text) {
    try {
        conditionRunner.waitFor(new Text(text));
    } catch(Throwable t) {
        throw new AssertionFailedError("Expecting text " + text + " failed to become true. Complete text [" + browser.getBodyText() + "]");
    }
}
+7

, /. , , - , , , . : , [] (, , ), , . , , , ( ) / .

:

  • unit test
  • / , ( )
  • : , ,

. , . , , ( ), , . , . , "" .

:

+2

? ? ?

Class Orchestrator implements AsynchCallback {

    TheAsycnhService myDelegate;  // initialised by injection

    public void doSomething(Request aRequest){
          myDelegate.doTheWork(aRequest, this)
    }

    public void tellMeTheResult(Response aResponse) {
          // process response
    }
}

-

 Orchestrator orch = new Orchestrator(mockAsynchService);

 orch.doSomething(request);

 // assertions here that the mockAsychService received the expected request

 // now either the mock really does call back
 // or (probably more easily) make explicit call to the tellMeTheResult() method

 // assertions here that the  Orchestrator did the right thing with the response

Note that there is no true asynch processing here, and the layout itself should not have any logic other than allowing the verification of the receipt of the correct request. For Unit test Orchestrator, this is enough.

I used this version of the idea when testing BPEL processes in WebSphere Process Server.

0
source

All Articles