I am using iPhone Sen testing framework for testing. I need to test the asynchronous responses coming from server. Can anyone help me to find out the way to test it.
Thank you
This may have been a duplicate question, but I don't agree with the answer to the original one. I've described why in length on that question.
In summary, creating a custom run loop for your tests is complicated and fragile. Your tests will run more consistently and more quickly if you remove the dependency on the external service that is returning the asynchronous responses and mimic the responses in your tests. This way your tests won't fail if the external service goes down, and your tests will run much more quickly.
There are libraries available that reopen classes like NSURLConnection and make this easy to do. It's also relatively simple to do for a single class (like NSURLConnection), thanks to the dynamic properties of Objective C. Here is an example.
I don't use Sen test because it doesn't run in a simulator or device (or at least didn't when I first started doing Objective C last year), instead I use GHUnit as a testing framework and OCMock as a mocking framework. GHUnit will run tests on the device which ensures that the code is correct for it. OCMock allows full mocking, partial mocking and method swizzling which are powerful tools for unit a test.
I think there are two parts to testing in this situation.
Unit testing the individual components (GHUnit and OCMock). Here you can call methods direct and simulate the environment you class will run in. So you don't need a server setup to test async calls. Just instantiate the class in a unit test and call it's methods.
Integration testing. (GHUnit only) Here you want to do a basic test to ensure that your understanding of the communication between your code and the server is correct. So this is where you do need a server. Depending on your needs, this may be a lot or a little amount of work. For example when I've done this I've just setup a glassfish server with an EJB3 bean to simulate the server I've going to connect to. The important thing in this is that the server you setup must behave exactly the same way as the final production server.
So basically it's a two pronged approach. Unit testing to check every nook and cranny of your code. Integration testing to ensure that the overall communication with the server is being handled correctly.
Using both is important because whilst unit testing can check functionality that is difficult to check with an integration test, it is only as accurate as your understanding of the communication between the class and server. So you need at least a basic integration test to confirm your understanding is correct. But don't waste time writing lots of integration tests to check every nook and cranny of the class. It's always much harder than a unit test.
I use this for testing async operations.