Skip to content

Commit 0610ec3

Browse files
committed
Merge pull request #101 from briancroom/test-case-terminology
Standardize usage of the term "test case" in the code and documentation
2 parents 244507b + 1da00f2 commit 0610ec3

File tree

6 files changed

+42
-39
lines changed

6 files changed

+42
-39
lines changed

Documentation/Linux.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestNSURL : XCTestCase {
2323
}
2424
```
2525

26-
Also, this version of XCTest does not use the external test runner binary. Instead, create your own executable which links `libXCTest.so`. In your `main.swift`, invoke the `XCTMain` function with an array of the test cases classes that you wish to run, wrapped by the `testCase` helper function. For example:
26+
Also, this version of XCTest does not use the external test runner binary. Instead, create your own executable which links `libXCTest.so`. In your `main.swift`, invoke the `XCTMain` function with an array of the tests from the `XCTestCase` subclasses that you wish to run, wrapped by the `testCase` helper function. For example:
2727

2828
```swift
2929
XCTMain([testCase(TestNSString.allTests), testCase(TestNSArray.allTests), testCase(TestNSDictionary.allTests)])
@@ -32,7 +32,7 @@ XCTMain([testCase(TestNSString.allTests), testCase(TestNSArray.allTests), testCa
3232
The `XCTMain` function does not return, and will cause your test app to exit with either `0` for success or `1` for failure. Command line arguments given to the executable can be used to select a particular test or test case to execute. For example:
3333

3434
```sh
35-
./FooTests FooTestCase/testFoo # Run a single test method
35+
./FooTests FooTestCase/testFoo # Run a single test case
3636
./FooTests FooTestCase # Run all the tests in FooTestCase
3737
```
3838

Sources/XCTest/TestFiltering.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,37 @@ internal struct TestFiltering {
3737

3838
static func filterTests(_ entries: [XCTestCaseEntry], filter: TestFilter) -> [XCTestCaseEntry] {
3939
return entries
40-
.map { testCase, tests in
41-
return (testCase, tests.filter { filter(testCase, $0.0) } )
40+
.map { testCaseClass, testCaseMethods in
41+
return (testCaseClass, testCaseMethods.filter { filter(testCaseClass, $0.0) } )
4242
}
43-
.filter { testCase, tests in
44-
return !tests.isEmpty
43+
.filter { _, testCaseMethods in
44+
return !testCaseMethods.isEmpty
4545
}
4646
}
4747
}
4848

49-
/// A selected test can be an entire test case, or a single test method
50-
/// within a test case.
49+
/// A selected test can be a single test case, or an entire class of test cases
5150
private struct SelectedTest {
52-
let testCaseName: String
53-
let testName: String?
51+
let testCaseClassName: String
52+
let testCaseMethodName: String?
5453
}
5554

5655
private extension SelectedTest {
5756
init?(selectedTestName: String) {
5857
let components = selectedTestName.characters.split(separator: "/").map(String.init)
5958
switch components.count {
6059
case 1:
61-
testCaseName = components[0]
62-
testName = nil
60+
testCaseClassName = components[0]
61+
testCaseMethodName = nil
6362
case 2:
64-
testCaseName = components[0]
65-
testName = components[1]
63+
testCaseClassName = components[0]
64+
testCaseMethodName = components[1]
6665
default:
6766
return nil
6867
}
6968
}
7069

71-
func matches(testCase: XCTestCase.Type, testName: String) -> Bool {
72-
return String(reflecting: testCase) == testCaseName && (self.testName == nil || testName == self.testName)
70+
func matches(testCaseClass: XCTestCase.Type, testCaseMethodName: String) -> Bool {
71+
return String(reflecting: testCaseClass) == testCaseClassName && (self.testCaseMethodName == nil || testCaseMethodName == self.testCaseMethodName)
7372
}
7473
}

Sources/XCTest/XCTestCase.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#endif
1919

2020
/// This is a compound type used by `XCTMain` to represent tests to run. It combines an
21-
/// `XCTestCase` subclass type with the list of test methods to invoke on the test case.
21+
/// `XCTestCase` subclass type with the list of test case methods to invoke on the class.
2222
/// This type is intended to be produced by the `testCase` helper function.
2323
/// - seealso: `testCase`
2424
/// - seealso: `XCTMain`
@@ -28,6 +28,10 @@ public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(
2828
// order for XCTAssert functions to report failures.
2929
internal var XCTCurrentTestCase: XCTestCase?
3030

31+
/// An instance of this class represents an individual test case which can be
32+
/// run by the framework. This class is normally subclassed and extended with
33+
/// methods containing the tests to run.
34+
/// - seealso: `XCTMain`
3135
public class XCTestCase: XCTest {
3236
private let testClosure: XCTestCase throws -> Void
3337

Sources/XCTest/XCTestMain.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
///
4343
/// XCTMain([ testCase(TestFoo.allTests) ])
4444
///
45-
/// Command line arguments can be used to select a particular test or test case to execute. For example:
45+
/// Command line arguments can be used to select a particular test case or class to execute. For example:
4646
///
47-
/// ./FooTests FooTestCase/testFoo # Run a single test method
47+
/// ./FooTests FooTestCase/testFoo # Run a single test case
4848
/// ./FooTests FooTestCase # Run all the tests in FooTestCase
4949
///
5050
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
@@ -75,10 +75,10 @@
7575
}
7676

7777
let filter = TestFiltering(selectedTestName: selectedTestName)
78-
for (testCaseType, tests) in TestFiltering.filterTests(testCases, filter: filter.selectedTestFilter) {
79-
let testCaseSuite = XCTestSuite(name: "\(testCaseType)")
80-
for (testName, testClosure) in tests {
81-
let testCase = testCaseType.init(name: testName, testClosure: testClosure)
78+
for (testCaseClass, testCaseMethods) in TestFiltering.filterTests(testCases, filter: filter.selectedTestFilter) {
79+
let testCaseSuite = XCTestSuite(name: "\(testCaseClass)")
80+
for (testName, testClosure) in testCaseMethods {
81+
let testCase = testCaseClass.init(name: testName, testClosure: testClosure)
8282
testCaseSuite.addTest(testCase)
8383
}
8484
currentTestSuite.addTest(testCaseSuite)

Tests/Functional/Observation/Selected/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SkippedTestCase: XCTestCase {
4444
}
4545

4646
func test_skipped() {
47-
XCTFail("This test method should not be executed.")
47+
XCTFail("This test case should not be executed.")
4848
}
4949
}
5050

@@ -65,7 +65,7 @@ class ExecutedTestCase: XCTestCase {
6565
}
6666

6767
func test_skipped() {
68-
XCTFail("This test method should not be executed.")
68+
XCTFail("This test case should not be executed.")
6969
}
7070
}
7171

Tests/Functional/SelectedTest/main.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %{swiftc} %s -o %{built_tests_dir}/SelectedTest
2-
// RUN: %{built_tests_dir}/SelectedTest SelectedTest.ExecutedTestCase/test_foo > %T/one_test_method || true
3-
// RUN: %{built_tests_dir}/SelectedTest SelectedTest.ExecutedTestCase > %T/one_test_case || true
2+
// RUN: %{built_tests_dir}/SelectedTest SelectedTest.ExecutedTestCase/test_foo > %T/one_test_case || true
3+
// RUN: %{built_tests_dir}/SelectedTest SelectedTest.ExecutedTestCase > %T/one_test_case_class || true
44
// RUN: %{built_tests_dir}/SelectedTest > %T/all || true
5-
// RUN: %{xctest_checker} -p "// CHECK-METHOD:" %T/one_test_method %s
6-
// RUN: %{xctest_checker} -p "// CHECK-TESTCASE:" %T/one_test_case %s
5+
// RUN: %{xctest_checker} -p "// CHECK-METHOD:" %T/one_test_case %s
6+
// RUN: %{xctest_checker} -p "// CHECK-CLASS:" %T/one_test_case_class %s
77
// RUN: %{xctest_checker} -p "// CHECK-ALL:" %T/all %s
88

99
#if os(Linux) || os(FreeBSD)
@@ -13,7 +13,7 @@
1313
#endif
1414

1515
// CHECK-METHOD: Test Suite 'Selected tests' started at \d+:\d+:\d+\.\d+
16-
// CHECK-TESTCASE: Test Suite 'Selected tests' started at \d+:\d+:\d+\.\d+
16+
// CHECK-CLASS: Test Suite 'Selected tests' started at \d+:\d+:\d+\.\d+
1717
// CHECK-ALL: Test Suite 'All tests' started at \d+:\d+:\d+\.\d+
1818
// CHECK-ALL: Test Suite '.*\.xctest' started at \d+:\d+:\d+\.\d+
1919

@@ -28,24 +28,24 @@ class ExecutedTestCase: XCTestCase {
2828
// CHECK-METHOD: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
2929
// CHECK-METHOD: Test Case 'ExecutedTestCase.test_foo' started at \d+:\d+:\d+\.\d+
3030
// CHECK-METHOD: Test Case 'ExecutedTestCase.test_foo' passed \(\d+\.\d+ seconds\).
31-
// CHECK-TESTCASE: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
32-
// CHECK-TESTCASE: Test Case 'ExecutedTestCase.test_bar' started at \d+:\d+:\d+\.\d+
33-
// CHECK-TESTCASE: Test Case 'ExecutedTestCase.test_bar' passed \(\d+\.\d+ seconds\).
31+
// CHECK-CLASS: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
32+
// CHECK-CLASS: Test Case 'ExecutedTestCase.test_bar' started at \d+:\d+:\d+\.\d+
33+
// CHECK-CLASS: Test Case 'ExecutedTestCase.test_bar' passed \(\d+\.\d+ seconds\).
3434
// CHECK-ALL: Test Suite 'ExecutedTestCase' started at \d+:\d+:\d+\.\d+
3535
// CHECK-ALL: Test Case 'ExecutedTestCase.test_bar' started at \d+:\d+:\d+\.\d+
3636
// CHECK-ALL: Test Case 'ExecutedTestCase.test_bar' passed \(\d+\.\d+ seconds\).
3737
func test_bar() {}
3838

39-
// CHECK-TESTCASE: Test Case 'ExecutedTestCase.test_foo' started at \d+:\d+:\d+\.\d+
40-
// CHECK-TESTCASE: Test Case 'ExecutedTestCase.test_foo' passed \(\d+\.\d+ seconds\).
39+
// CHECK-CLASS: Test Case 'ExecutedTestCase.test_foo' started at \d+:\d+:\d+\.\d+
40+
// CHECK-CLASS: Test Case 'ExecutedTestCase.test_foo' passed \(\d+\.\d+ seconds\).
4141
// CHECK-ALL: Test Case 'ExecutedTestCase.test_foo' started at \d+:\d+:\d+\.\d+
4242
// CHECK-ALL: Test Case 'ExecutedTestCase.test_foo' passed \(\d+\.\d+ seconds\).
4343
func test_foo() {}
4444
}
4545
// CHECK-METHOD: Test Suite 'ExecutedTestCase' passed at \d+:\d+:\d+\.\d+
4646
// CHECK-METHOD: \t Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
47-
// CHECK-TESTCASE: Test Suite 'ExecutedTestCase' passed at \d+:\d+:\d+\.\d+
48-
// CHECK-TESTCASE: \t Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
47+
// CHECK-CLASS: Test Suite 'ExecutedTestCase' passed at \d+:\d+:\d+\.\d+
48+
// CHECK-CLASS: \t Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
4949
// CHECK-ALL: Test Suite 'ExecutedTestCase' passed at \d+:\d+:\d+\.\d+
5050
// CHECK-ALL: \t Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
5151

@@ -70,8 +70,8 @@ XCTMain([
7070

7171
// CHECK-METHOD: Test Suite 'Selected tests' passed at \d+:\d+:\d+\.\d+
7272
// CHECK-METHOD: \t Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
73-
// CHECK-TESTCASE: Test Suite 'Selected tests' passed at \d+:\d+:\d+\.\d+
74-
// CHECK-TESTCASE: \t Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
73+
// CHECK-CLASS: Test Suite 'Selected tests' passed at \d+:\d+:\d+\.\d+
74+
// CHECK-CLASS: \t Executed 2 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
7575
// CHECK-ALL: Test Suite '.*\.xctest' passed at \d+:\d+:\d+\.\d+
7676
// CHECK-ALL: \t Executed 3 tests, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
7777
// CHECK-ALL: Test Suite 'All tests' passed at \d+:\d+:\d+\.\d+

0 commit comments

Comments
 (0)