简体   繁体   中英

How to list all test cases using xcodebuild without running?

Using xcodebuild I can run a specific test or group of tests. But is there a way to list all tests without running them, using xcodebuild or any other tool that comes with xcode? Facebook's xctool can do this but I hope to not take dependency on third party tools.

Better late than never - I also needed to do this and couldn't find a way using xcode, so I wrote a python script that parses the test files and gets the names of XCTest test functions:

import re
import os

all_tests = []
TEST_FILES = os.path.expanduser("~/git/ios-proj/Test")
test_case_pattern = re.compile(r"^\s*func\s(test\w*)\(\)[\s\w]*\{")
for test_file in os.listdir(TEST_FILES):
    all_tests += [test_case_pattern.match(line)[1] for line in
                 open(os.path.join(TEST_FILES, test_file), "r").readlines() if test_case_pattern.match(line)]
print(all_tests)

You can get the test names by using "strings". it's not an xcode command, but is normally available on the mac. Run "strings" on the following file and grep whatever marks your tests. in my case, all tests start with "test_":

strings <Tests-Target>-Runner.app/PlugIns/<Tests-Target>.xctest/<Tests-Target>|grep "test_"

an easy way to find this file is by running:

grep -r <single test name> <derived data folder for your project>

I cannot think of any way to sort automatically... but If you want to test one of the classes by one command So you can run your test one by one through this command :

xcodebuild test -destination 'platform=iOS Simulator,name=iPhone 7,OS=11.1' '-only-testing:APPNAME-TESTTARGET/NAMEOFTHECLASS'

also you can see your list of targets, builds configurations, and schemes by using this command :

 xcodebuild -list

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM