Skip to content

Commit 7f80b20

Browse files
committed
Add failing test for a new test case instance being used for each test
This matches Darwin XCTest behavior
1 parent c2c0da7 commit 7f80b20

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

Tests/Functional/TestCaseLifecycle/main.swift

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// CHECK: In tearDown\(\)
88
// CHECK: Test Case 'SetUpTearDownTestCase.test_hasValueFromSetUp' passed \(\d+\.\d+ seconds\).
99
// CHECK: Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
10-
// CHECK: Total executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
10+
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValue' started.
11+
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValue' passed \(\d+\.\d+ seconds\).
12+
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValueInAnotherTest' started.
13+
// CHECK: Test Case 'NewInstanceForEachTestTestCase.test_hasInitializedValueInAnotherTest' passed \(\d+\.\d+ seconds\).
14+
// CHECK: Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
15+
// CHECK: Total executed 3 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
1116

1217
#if os(Linux) || os(FreeBSD)
1318
import XCTest
@@ -41,4 +46,27 @@ class SetUpTearDownTestCase: XCTestCase {
4146
}
4247
}
4348

44-
XCTMain([SetUpTearDownTestCase()])
49+
class NewInstanceForEachTestTestCase: XCTestCase {
50+
var allTests: [(String, () throws -> Void)] {
51+
return [
52+
("test_hasInitializedValue", test_hasInitializedValue),
53+
("test_hasInitializedValueInAnotherTest", test_hasInitializedValueInAnotherTest),
54+
]
55+
}
56+
57+
var value = 1
58+
59+
func test_hasInitializedValue() {
60+
XCTAssertEqual(value, 1)
61+
value += 1
62+
}
63+
64+
func test_hasInitializedValueInAnotherTest() {
65+
XCTAssertEqual(value, 1)
66+
}
67+
}
68+
69+
XCTMain([
70+
SetUpTearDownTestCase(),
71+
NewInstanceForEachTestTestCase()
72+
])

0 commit comments

Comments
 (0)