Why are before- and afterEach locks called multiple times in unit testing with Quick?

I wrote a test case with some group examples, including beforeEachand afterEach. And I expect that each beforeEachand afterEachwill be called once for each it.

Alas, for one it beforeEachthey afterEachgot it several times.

I looked through some documentation (e.g. Quick in-house documentation and http://jasmine.imtqy.com/2.1/introduction.html ), but this does not help my reason.

Here is a small snippet demonstrating 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:

Console logs up

The above logs raise two questions:

  • , beforeEach afterEach; , , . ?

- , context , ... ?

, :

Console Logs After

- , ? ?


EDIT:

; 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:
:

- , context , ... ?

, , .


EDIT:

; :

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

, .

+4
1

. .

, . , , , .

:
, "tLog.info", . , . print (_:).

"TryQuickTest.swift" :

import XCTest
import Quick
import Nimble 

class TryQuickTest: QuickSpec {

    override func spec() {

        describe("blah") {
            beforeEach {
                print("describe before")
            }
            afterEach {
                print("describe after")
            }

            context("of blah2") {
                beforeEach {
                    print("context before")
                }
                afterEach {
                    print("context after")
                }

                it("first it should be like this") {
                    print("in the first `IT`")
                    XCTFail("Hey fail in first it")
                }

                it("second it should be like this") {
                    print("in the second `IT`")
                    XCTFail("Hey fail in second it")
                }
            }
        }   
    }    
}


:

Test Suite 'Selected tests' started at 2017-05-28 07:35:32.345
Test Suite 'PlayQuickTests.xctest' started at 2017-05-28 07:35:32.347
Test Suite 'TryQuickTest' started at 2017-05-28 07:35:32.348
Test Case '-[PlayQuickTests.TryQuickTest blah__of_blah2__first_it_should_be_like_this]' started.
describe before
context before
in the first `IT`
/Users/shisui/Developer/General/iOS_Swift/PlayQuick/PlayQuickTests/TryQuickTest.swift:35: error: -[PlayQuickTests.TryQuickTest blah__of_blah2__first_it_should_be_like_this] : failed - Hey fail in first it
context after
describe after
Test Case '-[PlayQuickTests.TryQuickTest blah__of_blah2__first_it_should_be_like_this]' failed (0.004 seconds).
Test Case '-[PlayQuickTests.TryQuickTest blah__of_blah2__second_it_should_be_like_this]' started.
describe before
context before
in the second `IT`
/Users/shisui/Developer/General/iOS_Swift/PlayQuick/PlayQuickTests/TryQuickTest.swift:40: error: -[PlayQuickTests.TryQuickTest blah__of_blah2__second_it_should_be_like_this] : failed - Hey fail in second it
context after
describe after
Test Case '-[PlayQuickTests.TryQuickTest blah__of_blah2__second_it_should_be_like_this]' failed (0.003 seconds).
Test Suite 'TryQuickTest' failed at 2017-05-28 07:35:32.359.
    Executed 2 tests, with 2 failures (0 unexpected) in 0.007 (0.010) seconds
Test Suite 'PlayQuickTests.xctest' failed at 2017-05-28 07:35:32.359.
    Executed 2 tests, with 2 failures (0 unexpected) in 0.007 (0.012) seconds
Test Suite 'Selected tests' failed at 2017-05-28 07:35:32.374.
    Executed 2 tests, with 2 failures (0 unexpected) in 0.007 (0.029) seconds

. .

"it". :

Test Suite 'Selected tests' started at 2017-05-28 07:56:09.214
Test Suite 'PlayQuickTests.xctest' started at 2017-05-28 07:56:09.215
Test Suite 'TryQuickTest' started at 2017-05-28 07:56:09.215
Test Case '-[PlayQuickTests.TryQuickTest blah__of_blah2__first_it_should_be_like_this]' started.
describe before
context before
in the first `IT`
/Users/shisui/Developer/General/iOS_Swift/PlayQuick/PlayQuickTests/TryQuickTest.swift:35: error: -[PlayQuickTests.TryQuickTest blah__of_blah2__first_it_should_be_like_this] : failed - Hey fail in first it
context after
describe after
Test Case '-[PlayQuickTests.TryQuickTest blah__of_blah2__first_it_should_be_like_this]' failed (0.006 seconds).
Test Suite 'TryQuickTest' failed at 2017-05-28 07:56:09.222.
    Executed 1 test, with 1 failure (0 unexpected) in 0.006 (0.007) seconds
Test Suite 'PlayQuickTests.xctest' failed at 2017-05-28 07:56:09.224.
    Executed 1 test, with 1 failure (0 unexpected) in 0.006 (0.009) seconds
Test Suite 'Selected tests' failed at 2017-05-28 07:56:09.224.
    Executed 1 test, with 1 failure (0 unexpected) in 0.006 (0.011) seconds
+2

Source: https://habr.com/ru/post/1677448/


All Articles