Asynchronous testing for iOS
After a long time thinking and talking about it, I’ve started to add some unit testing to WordPress for iOS. Not long after I started, I hit my first roadblock: apparently the included SenTestingKit framework doesn’t support asynchronous testing.
I had a piece of test code like this:
Soon I noticed those assertions were never being triggered, and the reason is the test finished before those callback blocks were called.
After a bit of googling I came across SenTestingKit in Xcode 4: Asynchronous testing?, and tried GHUnit, since it supports asynchronous testing. But I gave up too quickly.
GHUnit is not a drop-in replacement for SenTestingKit, and while the assertion macros are similar, the way of running the tests is not and I was happy with SenTestingKit so far.
So I went for the next best thing: using semaphores to wait for those blocks. And I wrote some helper macros for this
And the new (working) test looks like this: