How can I test my service class with using Quick? #asynchronous

754 views Asked by At

My problem is to test if my get service is working or not? The technique I want to use asynchronous test in Quick/Nimble (Swift)

I wonder how to set and get variable of test class? and how to test it? (async)

As you see in the code t_items is variable of test class.When I test it it FAILS.

But when I test the t_items variable in my service (production class) It PASSES I set this t_items var in production class but I don't need & want it.

Why would't I get my data returned by block? What do I miss?

Thanks

it("getlist fetches data") {

    var service = Service()

    dispatch_async(dispatch_get_global_queue(0, 0), { () -> Void in
        service.getList("Test", success: { (data) -> Void in

            t_items = data as? NSMutableArray // t_times declared in before each{}

        }, error: { (error) -> Void in

        })
    })

    expect(t_items.count).toEventually(equal(3), timeout:3) // error FAILS
    expect(service.t_items).toEventually(equal(3), timeout: 3)// PASSES

}
0

There are 0 answers