Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all test cases using xcodebuild without running?

Tags:

ios

xcodebuild

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.

like image 449
Haitao Li Avatar asked Mar 19 '26 16:03

Haitao Li


1 Answers

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)
like image 66
Daniel Robinson Avatar answered Mar 21 '26 07:03

Daniel Robinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!