Skip to content

Commit 7d477ed

Browse files
committed
Add functional test for the current behavior of setUp() and tearDown()
1 parent 0970216 commit 7d477ed

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %{swiftc} %s -o %{built_tests_dir}/TestCaseLifecycle
2+
// RUN: %{built_tests_dir}/TestCaseLifecycle > %t || true
3+
// RUN: %{xctest_checker} %t %s
4+
// CHECK: Test Case 'SetUpTearDownTestCase.test_hasValueFromSetUp' started.
5+
// CHECK: In setUp\(\)
6+
// CHECK: In test_hasValueFromSetUp\(\)
7+
// CHECK: In tearDown\(\)
8+
// CHECK: Test Case 'SetUpTearDownTestCase.test_hasValueFromSetUp' passed \(\d+\.\d+ seconds\).
9+
// 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
11+
12+
#if os(Linux) || os(FreeBSD)
13+
import XCTest
14+
#else
15+
import SwiftXCTest
16+
#endif
17+
18+
class SetUpTearDownTestCase: XCTestCase {
19+
var allTests: [(String, () throws -> Void)] {
20+
return [
21+
("test_hasValueFromSetUp", test_hasValueFromSetUp),
22+
]
23+
}
24+
25+
var value = 0
26+
27+
func setUp() {
28+
print("In \(__FUNCTION__)")
29+
value = 42
30+
}
31+
32+
func tearDown() {
33+
print("In \(__FUNCTION__)")
34+
}
35+
36+
func test_hasValueFromSetUp() {
37+
print("In \(__FUNCTION__)")
38+
XCTAssertEqual(value, 42)
39+
}
40+
}
41+
42+
XCTMain([SetUpTearDownTestCase()])

XCTest.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
/* Begin PBXFileReference section */
2828
342A33611C470D91001AA02A /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
29+
342A33631C47383E001AA02A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
2930
5B5D86DB1BBC74AD00234F36 /* SwiftXCTest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftXCTest.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3031
9F320B0D1C4714EC00AB3456 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
3132
B1384A411C1B3E8700EDF031 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
@@ -70,6 +71,14 @@
7071
path = FailureMessagesTestCase;
7172
sourceTree = "<group>";
7273
};
74+
342A33621C47343C001AA02A /* TestCaseLifecycle */ = {
75+
isa = PBXGroup;
76+
children = (
77+
342A33631C47383E001AA02A /* main.swift */,
78+
);
79+
path = TestCaseLifecycle;
80+
sourceTree = "<group>";
81+
};
7382
5B5D86D11BBC74AD00234F36 = {
7483
isa = PBXGroup;
7584
children = (
@@ -146,6 +155,7 @@
146155
DADB975D1C44BE73005E68B6 /* FailingTestSuite */,
147156
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */,
148157
342A33601C470D1E001AA02A /* FailureMessagesTestCase */,
158+
342A33621C47343C001AA02A /* TestCaseLifecycle */,
149159
DA78F7ED1C4039410082E15B /* xctest_checker */,
150160
);
151161
path = Functional;

0 commit comments

Comments
 (0)