如何使用Quick测试我的服务类? #异步

时间:2015-06-15 21:06:54

标签: swift quick-nimble

我的问题是测试我的获取服务是否正常工作? 我想在Quick / Nimble(Swift)中使用异步测试的技术

我想知道如何设置和获取测试类的变量?以及如何测试? (异步)

正如您在代码中看到的那样 t_items 测试类的变量。当我测试它时, FAILS

但是当我在我的服务中测试 t_items变量(生产类)时 PASSES 我在生产类中设置了这个t_items var但我不需要& ;想要它。

为什么我不能通过块返回我的数据? 我错过了什么?

由于

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 个答案:

没有答案
相关问题