You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running on the Objective-C runtime, XCTest is able to find all of your tests by simply asking the runtime for the subclasses of `XCTestCase`. It then finds the methods that start with the string `test`. This functionality is not currently present when running on the Swift runtime. Therefore, you must currently provide an additional property, conventionally named `allTests`, in your `XCTestCase` subclass. This method lists all of the tests in the test class. The rest of your test case subclass still contains your test methods.
// Write your test here. Most of the XCTAssert macros you are familiar with are available.
19
+
XCTAssertTrue(theBestNumber ==42, "The number is wrong")
20
+
}
21
+
22
+
// Other tests go here
23
+
}
24
+
```
25
+
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:
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:
33
+
34
+
```sh
35
+
./FooTests FooTestCase/testFoo # Run a single test method
36
+
./FooTests FooTestCase # Run all the tests in FooTestCase
37
+
```
38
+
39
+
We are currently investigating ideas on how to make these additional steps for test discovery automatic when running on the Swift runtime.
Copy file name to clipboardExpand all lines: README.md
+18-84Lines changed: 18 additions & 84 deletions
Original file line number
Diff line number
Diff line change
@@ -6,113 +6,47 @@ This version of XCTest uses the same API as the XCTest you are familiar with fro
6
6
7
7
## Current Status and Project Goals
8
8
9
-
This project is the very earliest stages of development. It is scheduled to be part of the Swift 3 release.
9
+
This project is in the very earliest stages of development. It is scheduled to be part of the Swift 3 release.
10
10
11
11
Only the most basic functionality is currently present. This year, we have the following goals for the project:
12
12
13
-
* Finish implementing support for the most important non-UI testing APIs present in XCTest for Xcode
13
+
* Finish implementing support for the most important non-UI testing APIs present in XCTest for Xcode.
14
14
* Develop an effective solution to the problem of test discoverability without the Objective-C runtime.
15
15
* Provide support for efforts to standardize test functionality across the Swift stack.
16
16
17
+
For more details, visit the `Documentation` directory.
18
+
17
19
## Using XCTest
18
20
19
21
Your tests are organized into a simple hierarchy. Each `XCTestCase` subclass has a set of `test` methods, each of which should test one part of your code.
20
22
21
23
You can find all kinds of useful information on using XCTest in [Apple's documentation](https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/03-testing_basics.html).
22
24
23
-
The rest of this document will focus on how this version of XCTest differs from the one shipped with Xcode.
24
-
25
-
## Working on XCTest
26
-
27
-
### On Linux
28
-
29
-
XCTest can be built as part of the overall Swift package. When following [the instructions for building Swift](http://www.github.com/apple/swift), pass the `--xctest` option to the build script:
30
-
31
-
```sh
32
-
swift/utils/build-script --xctest
33
-
```
34
-
35
-
If you want to build just XCTest, use the `build_script.py` script at the root of the project. The `master` version of XCTest must be built with the `master` version of Swift. XCTest has a dependency upon Foundation, so you must have built the `master` version of that as well.
36
-
37
-
If your install of Swift is located at `/swift` and you wish to install XCTest into that same location, here is a sample invocation of the build script:
You may add tests for XCTest by including them in the `Tests/Functional/` directory. For an example, see `Tests/Functional/SingleFailingTestCase`.
27
+
To contribute, you'll need to be able to build this project and and run its test suite. The easiest way to do so is via the Swift build script.
58
28
59
-
### On OS X
29
+
First, follow [the instructions in the Swift README](https://github.com/apple/swift/blob/master/README.md) to build Swift from source. Confirm you're able to build the Swift project using `utils/build-script -R`.
60
30
61
-
You may build XCTest via the "SwiftXCTest" scheme in `XCTest.xcworkspace`. The workspace assumes that Foundation and XCTest are checked out from GitHub in sibling directories. For example:
31
+
Once you are able to build the Swift project, build XCTestand run its tests:
Unlike on Linux, you do not need to build Foundation prior to building XCTest. The "SwiftXCTest" Xcode scheme takes care of that for you.
71
-
72
-
To run the tests on OS X, build and run the `SwiftXCTestFunctionalTests` target in the Xcode workspace. You may also run them via the command line:
38
+
This project is only guaranteed to build with the very latest commit on the Swift and swift-corelibs-foundation `master` branches. You may update to the latest commits using the Swift `utils/update-checkout` script:
When adding tests to the `Tests/Functional` directory, make sure they can be opened in the `XCTest.xcworkspace` by adding references to them, but do not add them to any of the targets.
79
-
80
-
### Additional Considerations for Swift on Linux
81
-
82
-
When running on the Objective-C runtime, XCTest is able to find all of your tests by simply asking the runtime for the subclasses of `XCTestCase`. It then finds the methods that start with the string `test`. This functionality is not currently present when running on the Swift runtime. Therefore, you must currently provide an additional property, conventionally named `allTests`, in your `XCTestCase` subclass. This method lists all of the tests in the test class. The rest of your test case subclass still contains your test methods.
// Write your test here. Most of the XCTAssert macros you are familiar with are available.
98
-
XCTAssertTrue(theBestNumber ==42, "The number is wrong")
99
-
}
100
-
101
-
// Other tests go here
102
-
}
41
+
$ ../swift/utils/update-checkout
103
42
```
104
43
105
-
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:
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:
46
+
To browse files in this project using Xcode, use `XCTest.xcworkspace`. You may build the project using the "SwiftXCTest" scheme. Run the "SwiftXCTestFunctionalTests" scheme to run the tests.
112
47
113
-
```sh
114
-
./FooTests FooTestCase/testFoo # Run a single test method
115
-
./FooTests FooTestCase # Run all the tests in FooTestCase
116
-
```
48
+
However, in order to successfully build the project in Xcode, **you must use an Xcode toolchain with an extremely recent version of Swift**. The Swift website provides [Xcode toolchains to download](https://swift.org/download/#latest-development-snapshots), as well as [instructions on how to use Xcode with those toolchains](https://swift.org/download/#apple-platforms). Swift development moves fairly quickly, and so even a week-old toolchain may no longer work.
117
49
118
-
We are currently investigating ideas on how to make these additional steps for test discovery automatic when running on the Swift runtime.
50
+
> If none of the toolchains available to download are recent enough to build XCTest, you may build your own toolchain by using [the `utils/build-toolchain` script in the Swift repository](https://github.com/apple/swift/blob/master/utils/build-toolchain).
51
+
>
52
+
> Keep in mind that the build script invocation in "Contributing to XCTest" above will always work, regardless of which Swift toolchains you have installed. The Xcode workspace exists simply for the convenience of contibutors. It is not necessary to successfully build this project in Xcode in order to contribute.
0 commit comments