Skip to content

afterSuite runs after every example #1312

@spikeburton

Description

@spikeburton
  • I have read CONTRIBUTING and have done my best to follow them.

What did you do?

import Quick
@testable import QuickExample

class TestConfig: QuickConfiguration {
    override class func configure(_ configuration: QCKConfiguration) {
        configuration.beforeSuite {
            print("global before suite")
        }

        configuration.afterSuite {
            print("global after suite")
        }
    }
}

final class MySpec: AsyncSpec {
    override class func spec() {
        beforeSuite {
            print("spec before suite")
        }

        afterSuite {
            print("spec after suite")
        }

        it("foo") {
            print("hello foo")
        }

        it("bar") {
            print("hello bar")
        }
    }
}

What did you expect to happen?

The afterSuite code should run only once after all examples have run in the spec.

What actually happened instead?

The afterSuite code is run after every example:

❯ swift test
Building for debugging...
[8/8] Linking QuickExamplePackageTests
Build complete! (0.53s)
Test Suite 'All tests' started at 2024-11-23 14:36:18.436.
Test Suite 'QuickExamplePackageTests.xctest' started at 2024-11-23 14:36:18.436.
Test Suite 'MySpec' started at 2024-11-23 14:36:18.436.
Test Case '-[QuickExampleTests.MySpec foo]' started.
Test Case '-[QuickExampleTests.MySpec foo]' passed (0.001 seconds).
Test Case '-[QuickExampleTests.MySpec bar]' started.
Test Case '-[QuickExampleTests.MySpec bar]' passed (0.000 seconds).
Test Suite 'MySpec' passed at 2024-11-23 14:36:18.437.
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'QuickExamplePackageTests.xctest' passed at 2024-11-23 14:36:18.437.
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'All tests' passed at 2024-11-23 14:36:18.437.
	 Executed 2 tests, with 0 failures (0 unexpected) in 0.001 (0.002) seconds
global before suite
spec before suite
hello foo
global after suite
spec after suite
hello bar
global after suite
spec after suite

Environment

List the software versions you're using:

  • Quick: 7.6.2
  • Nimble: 13.6.2
  • Xcode Version: 15.2
  • Swift Version: v5.9.2
❯ swift --version
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Please also mention which package manager you used and its version. Delete the
other package managers in this list:

❯ swift build --version
Swift Package Manager - Swift 5.9.0

Project that demonstrates the issue

https://github.com/spikeburton/swift-quick-example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions