我编写了一个测试用例,其中包含一些示例组,包括beforeEach
and afterEach
。
我期望每个beforeEach
and afterEach
每个都会被调用一次it
.
唉,对于一个人来说it
the beforeEach
and afterEach
被多次打电话。
我查看了一些文档(即 Quick 自己的文档和http://jasmine.github.io/2.1/introduction.html http://jasmine.github.io/2.1/introduction.html),但这些对我的事业没有帮助。
这是一个小片段,演示了这一点:
类 CheckerTests: QuickSpec {
override func spec() {
describe("something") {
beforeEach {
tLog.info("describe before")
}
afterEach {
tLog.info("describe after")
}
context("of something") {
beforeEach {
tLog.info("context before")
}
afterEach {
tLog.info("context after")
}
it("should behave like something") {
tLog.info("in the `IT`")
expect(true).to(beTrue())
}
}
}
}
}
我的控制台日志:
上述日志提出了两个问题:
- 我不知道when
beforeEach
and afterEach
现在被召唤;我也不知道为什么我看到多个日志调用它们。为什么他们会被多次调用?
- The above logs show that the context
's after block is called before the example passes...shouldn't that happen after the example?
从我的代码片段中,我希望日志返回:
有人能解释一下这里发生了什么吗?这是正确的行为吗?
EDIT:
正如评论所建议的;我还添加了一个日志inside the it
示例(请参阅上面修改后的代码片段)。
这给了我以下日志:
Test Suite 'CheckerTests' started at 2017-05-18 13:35:29.025
Test Case '-[CheckerTests something__of_something__should_behave_like_something]' started.
13:35:29.046 ???? INFO CheckerTests.spec():21 - describe before
13:35:29.046 ???? INFO CheckerTests.spec():21 - describe before
13:35:29.048 ???? INFO CheckerTests.spec():29 - context before
13:35:29.048 ???? INFO CheckerTests.spec():29 - context before
13:35:29.048 ???? INFO CheckerTests.spec():36 - in the `IT`
13:35:29.048 ???? INFO CheckerTests.spec():36 - in the `IT`
13:35:29.049 ???? INFO CheckerTests.spec():32 - context after
1Test Case '-[CheckerTests something__of_something__should_behave_like_something]' passed (0.024 seconds).
3:35:29.049 ???? INFO CheckerTests.spec():32 - context after
13:35:29.050 ???? INFOTest Suite 'CheckerTests' passed at 2017-05-18 13:35:29.050.
Executed 1 test, with 0 failures (0 unexpected) in 0.024 (0.025) seconds
CheckerTests.spec():24 - describe after
13:35:29.050 \360\237\222Test Suite 'CheckerTests.xctest' passed at 2017-05-18 13:35:29.051.
Executed 1 test, with 0 failures (0 unexpected) in 0.024 (0.026) seconds
\231 INFO CheckerTests.spec():24 - describe after
Test Suite 'Selected tests' passed at 2017-05-18 13:35:29.051.
Executed 1 test, with 0 failures (0 unexpected) in 0.024 (0.029) seconds
上面的日志显示该示例运行了两次,这让我更加困惑。
EDIT:
其中一个问题已得到解答:
- The above logs show that the context
's after block is called before the example passes...shouldn't that happen after the example?
测试似乎按正确的顺序进行,因此回答了上述问题。
EDIT:
以供参考;这就是我的 Podfile 的样子:
def pods_for_testing
pod 'Quick'
pod 'Nimble'
pod 'KIF'
end
target 'Checker' do
project 'Checker.xcodeproj', 'dev' => :debug, 'ntrl' => :debug, 'acpt' => :release, 'prod' => :release, 'prod appstore' => :release
pod 'SQLCipher'
pod 'UrbanAirship-iOS-SDK'
pod 'TBXML', :inhibit_warnings => true
pod 'SSZipArchive'
pod 'Google/Analytics'
pod 'Moya', '>= 8.0'
pod 'Unbox'
pod 'ProcedureKit'
pod 'ProcedureKit/Mobile'
pod 'SwiftyBeaver'
pod 'OHHTTPStubs'
pod 'OHHTTPStubs/Swift'
target 'CheckerTests' do
inherit! :search_paths
pods_for_testing
end
target 'CheckerUITests' do
inherit! :search_paths
pods_for_testing
end
end
除此之外,我不确定还有哪些其他设置可能会影响测试。