You can achieve this using XCTestExpectation (with Xcode 6) .
How it works:
We create an instance XCTestExpectationthat works like a timer. Your test will never end until one of two cases occurs:
XCTestExpectation.fulfill() called- you have a timeout defined using
waitForExpectationsWithTimeout, and therefore the test will fail
How to use XCTestExpectation
Step 1
( WmBuildGroupsTask):
protocol MyCallback{
func onDone(results: String)
}
.
2
Unitest :
class Test_WmBuildGroupsTask : XCTestCase, MyCallback {
}
3
XCTestExpectation ( Test_WmBuildGroupsTask):
var theExpectation:XCTestExpectation?
onDone():
func onDone(results: String){
theExpectation?.fulfill()
}
4
:
func test___WmBuildGroupsTask() {
theExpectation = expectationWithDescription("initialized")
var task:WmBuildGroupsTask = WmBuildGroupsTask()
task.delegate = self
task.execute();
waitForExpectationsWithTimeout(500, { error in XCTAssertNil(error, "Oh, we got timeout")
})
}
, WmBuildGroupsTask:
5
:
var delegate:MyCallback?
onPostExecute :
func onPostExecute(transferItem:WmTransferItem){
delegate?.onDone("finished")
}
.
()