Skip to content

Commit f262af3

Browse files
committed
Add functional test for the current behavior of setUp() and tearDown()
1 parent e5cf2f4 commit f262af3

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}/SetUpTearDownTestCase
2+
// RUN: %{built_tests_dir}/SetUpTearDownTestCase > %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
@@ -25,6 +25,7 @@
2525
/* End PBXContainerItemProxy section */
2626

2727
/* Begin PBXFileReference section */
28+
342A33631C47383E001AA02A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
2829
5B5D86DB1BBC74AD00234F36 /* SwiftXCTest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftXCTest.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2930
9F320B0D1C4714EC00AB3456 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
3031
B1384A411C1B3E8700EDF031 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
@@ -61,6 +62,14 @@
6162
/* End PBXFrameworksBuildPhase section */
6263

6364
/* Begin PBXGroup section */
65+
342A33621C47343C001AA02A /* SetUpTearDownTestCase */ = {
66+
isa = PBXGroup;
67+
children = (
68+
342A33631C47383E001AA02A /* main.swift */,
69+
);
70+
path = SetUpTearDownTestCase;
71+
sourceTree = "<group>";
72+
};
6473
5B5D86D11BBC74AD00234F36 = {
6574
isa = PBXGroup;
6675
children = (
@@ -136,6 +145,7 @@
136145
9F320B0C1C4714EC00AB3456 /* ErrorHandling */,
137146
DADB975D1C44BE73005E68B6 /* FailingTestSuite */,
138147
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */,
148+
342A33621C47343C001AA02A /* SetUpTearDownTestCase */,
139149
DA78F7ED1C4039410082E15B /* xctest_checker */,
140150
);
141151
path = Functional;

0 commit comments

Comments
 (0)