ios - Async method testing using XCTest -


i new xctest , started writing test cases. have written couple of functional test cases, got stuck in below async method call. read xctestexpectation class reference not able mock properly.

it helpful if know how test below method.

here details of method want test,

- (void)getstudentinfo:(void (^)(bool))success failure:(void (^)(nserror *error))failure {      // request formation code    // here have post call afnetworking      [httpsessionmanager post:uri    parameters:para       success:^(nsurlsessiondatatask *task, id responseobject) {        failure:^(nsurlsessiondatatask *task, nserror *error) {        }]      } 

you need xctest expectations provide support async testing. here simplified example (in swift, same applies objective-c)

func testasync() {      let expectation = expectationwithdescription("waiting something")      let someobject = ...     someobject.dosomethingwithcompletion({ () in             expectation.fulfill()         })      waitforexpectationswithtimeout(3.0, handler: nil)      // verify results } 

the simple explanation test wait @ waitfor... until fulfil() method called. or timeout , throw error.

you can set expectations on notifications , properties. check xctest class doco details.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -