I want to test drive some Swift examples using XCTest from the command line if possible.
import XCTest class LeapTest : XCTestCase { func testVanillaLeapYear() { let year = Year(calendarYear: 1996) XCTAssertTrue(year.isLeapYear); } }
I'd love to run it from the command line.
I already set Xcode to use the developer tools in the beta:
sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/
If I naively try and run it it goes like this
$ xcrun swift LeapTest.swift LeapTest.swift:1:8: error: cannot load underlying module for 'XCTest' import XCTest ^
Any way to run it directly from the CLI? Or do I have to create a Xcode project?
⌘U will build and run all your test cases. It is the most commonly used shortcut when creating unit test cases. It is equivalent to ⌘R (build & run) while doing app development. You can use this shortcut to build your test target and run all the test cases in your test target.
To run the tests from the command line, first cd to the exercise directory (for example, ~/exercism/swift/exercises/hello-world/), then execute swift test . This will compile the files in the Sources directory and execute the tests in the Tests directory. Alternatively, open the Xcode project and press Command-U.
I think the issue is you have your test.swift file under the main project's target membership. Make sure your swift test files belong to the Test target only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With