Search code examples
objective-cunit-testingocunit

SenTestingKit in Xcode 4: Asynchronous testing?


I have been searching for a way to use SenTestingKit to do some integration testing between my client-side code and our server. I haven't had any luck. It seems that once the code is run in a method, the object gets destroyed. This means that any asynchronous responses never call the selectors.

Questions:

  1. Is there a way to keep the object instantiated until such time as I see fit to destroy it - ie. after the tests have completed?
  2. If not, how could I create a class that blocks (ie. acts synchronously) until the tests are completed?

FYI, I'm running a test server where I know the expected results.

I've done a fair bit of Googling but haven't seen proof one way or another about this. I'm sure others would be interested as well.


Solution

  • Two options:

    • switch to GHUnit, which actually contains support for waiting for asynchronous events
    • narrow the design of your tests so that you can test things as they stand. E.g. test that your controller code causes a selector to be detached and run, and (separately) test that this selector does what it ought. If both of those things work, then you can be confident that your controller detaches the correct work.