簡體   English   中英

如何使用Xcode 5從命令行運行xctest?

[英]How do I run xctest from the command-line with Xcode 5?

我找到了一個名為“xctest”的命令行工具,它顯然可以在你的項目中運行單元測試。 此可執行文件位於此處

/Applications/Xcode.app/Contents/Developer/usr/bin/xctest

當我嘗試在我的xctest包上運行此可執行文件時,我正在使用:

$ ./xctest /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest

但是,我得到以下輸出:

Test Suite '(null)' started at 2013-11-14 21:16:45 +0000
Test Suite '(null)' finished at 2013-11-14 21:16:45 +0000.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds

據我所知,xctest沒有手冊頁,但在命令行輸入./xctest會產生:

Usage: xctest [--test Self | All | None | <TestCaseClassName/testMethodName>] <path of unit to be tested>

特別是,我希望能夠在測試類中測試一個特定的方法,這就是為什么我想使用這個xctest命令。

我確實看到有一種方法可以從命令行運行所有測試,如:

$ xcodebuild test -scheme MyApp

這將運行所有單元測試並正常工作(我看到我的單元測試結果,與使用xctest時不同)。 但我對能夠從命令行運行單個測試方法感興趣,例如:

$ ./xctest --test MyAppTests/testExample  /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest

盡管使用消息說-XCTest是您需要的參數:

xctest -XCTest MyAppTests/testExample testbundle.xctest

要直接調用xctest工作,您可能還需要將DYLD_FRAMEWORK_PATHDYLD_LIBRARY_PATH設置為構建的產品目錄。 通常,您需要使用與Xcode相同的參數和環境,您可以通過在其中一個測試中放置斷點,通過Xcode運行它們,然后為[NSProcessInfo processInfo]打印出argumentsenvironment的值來看到這一點。

為了避免弄亂所有注意事項,您還可以在Xcode中修改方案以僅運行特定測試。 在Product> Scheme> Edit Scheme下,選擇Test操作並展開測試包。 您可以使用復選框選擇要運行的測試,然后xcodebuild的測試操作將僅運行這些測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM