Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在Kiwi/快速测试框架中,beforeach方法的用途是什么?_Swift_Unit Testing - Fatal编程技术网

Swift 在Kiwi/快速测试框架中,beforeach方法的用途是什么?

Swift 在Kiwi/快速测试框架中,beforeach方法的用途是什么?,swift,unit-testing,Swift,Unit Testing,为什么在Kiwi和Quick等测试框架中使用beforeach beforeEach { let storyboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType)) let navigationController = storyboard.instantiateInitialViewController() as

为什么在Kiwi和Quick等测试框架中使用beforeach

beforeEach {
            let storyboard = UIStoryboard(name: "Main",
                bundle: NSBundle(forClass: self.dynamicType))
            let navigationController = storyboard.instantiateInitialViewController() as UINavigationController
            viewController = navigationController.topViewController as ViewController

            UIApplication.sharedApplication().keyWindow!.rootViewController = navigationController
            let _ = navigationController.view
            let _ = viewController.view
        }

示例代码取自:

相当于苹果的测试框架设置。它在每次测试之前执行,以设置将在每次测试中使用的组件和模拟

根据Kiwi的:

beforeachablock在所有封闭上下文中的每个it块之前运行。实际设置特定上下文的代码应该放在这里

这有助于避免代码重复,并且测试中有一个标准设置

在您共享的代码段中,beforeach方法使用从情节提要中提取的rootViewController设置UINavigationController。它还加载视图,以便测试可以访问插座等组件