How can I run XCTest for a swift application from the command line?

后端 未结 2 571
有刺的猬
有刺的猬 2020-12-29 02:28

I want to test drive some Swift examples using XCTest from the command line if possible.

import XCTest

class LeapTest : XCTestCase {

    func testVanillaL         


        
相关标签:
2条回答
  • 2020-12-29 03:18

    I was able to get your XCTestCase compiling with the following command:

    swiftc \
    -F/Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks \
    -Xlinker -rpath -Xlinker /Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks \
    -lswiftCore LeapTest.swift \
    -o LeapTests
    

    Then you can execute the tests with xctest:

    xcrun xctest LeapTests
    

    And to break down those swiftc command line options:

    1. -F... adds XCTest.framework to the framework search paths, enabling it to be imported from Swift
    2. -Xlinker -rpath ... makes sure the XCTest shared library can be found at load time
    3. Without explicitly specifying -lswiftCore, I found that xctest would crash when it tried to run the test suite

    Hope that helps!

    0 讨论(0)
  • 2020-12-29 03:18

    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.

    0 讨论(0)
提交回复
热议问题