[英]How can I run XCTest for a swift application from the command line?
我想從命令行使用XCTest測試一些Swift示例,如果可能的話。
import XCTest
class LeapTest : XCTestCase {
func testVanillaLeapYear() {
let year = Year(calendarYear: 1996)
XCTAssertTrue(year.isLeapYear);
}
}
我喜歡從命令行運行它。
我已經將Xcode設置為使用測試版中的開發人員工具:
sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/
如果我天真地嘗試並運行它就像這樣
$ xcrun swift LeapTest.swift
LeapTest.swift:1:8: error: cannot load underlying module for 'XCTest'
import XCTest
^
有沒有辦法直接從CLI運行它? 或者我是否必須創建Xcode項目?
我認為問題是你在主項目的目標成員資格下有你的test.swift文件。 確保您的swift測試文件僅屬於Test目標。
我能夠使用以下命令進行XCTestCase編譯:
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
然后你可以用xctest
執行測試:
xcrun xctest LeapTests
並打破那些swiftc
命令行選項:
-F...
將XCTest.framework添加到框架搜索路徑,使其能夠從Swift導入 -Xlinker -rpath ...
確保在加載時可以找到XCTest共享庫 -lswiftCore
,我發現xctest
在嘗試運行測試套件時會崩潰 希望有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.