I wrote a test case with some example groups including beforeEach
and afterEach
.
And I expected that each beforeEach
and afterEach
would be called once for each it
.
Alas, for a single it
the beforeEach
and afterEach
got called multiple times.
I've looked at some documentation (i.e. Quick's own documentation and http://jasmine.github.io/2.1/introduction.html), but those don't help my cause.
Here is a small snippet that demonstrates this:
class 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())
}
}
}
}
}
My console logs:
The above logs raise two questions:
- I'm not sure when
beforeEach
andafterEach
are called now; nor do I know why I see multiple logs calling them. How come they are called multiple times?
- The above logs show that the context
's after block is called before the example passes...shouldn't that happen after the example?
From my code snippet I would've expect the logs to return:
Could someone explain what happens here? And is this the correct behaviour?
EDIT:
As suggested by a comment; I also added a log inside the it
example (see the revised code snippet above).
Which gives me the following logs:
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
The above logs show me that the example is running twice, which confuses me even more.
EDIT:
One of the questions is answered:
- The above logs show that the context
's after block is called before the example passes...shouldn't that happen after the example?
It seems the tests follow up in the correct order, so that answers the above question.
EDIT:
For reference; this is what my Podfile looks like:
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
Next to this I'm not sure what other settings could be affecting the tests.
print("test print")
in theit
, when does it print? The fact that the test library prints information about test pass after cleanup seems fine to me. β Airliahit
, the print just gets printed twice as well. It just seems as if theit
gets called twice or something. β Restorativecontext after
is irrelevant. Now, only problem that remains is the fact that the methods are executed twice. β Airliahdetail steps
might be useful. https://mcmap.net/q/1915204/-how-to-reliably-install-and-setup-quick-test-framework-on-xcode-8 β Kwangchow