For our upcoming NetworkConnectivityTests, we want to run a predefined list of test cases for all of the faults currently known to the SDK test proxy server.
On Android, we use JUnit’s @Parameterized functionality to do this. There isn’t a corresponding thing in XCTest, so here we build one.
The general approach (where to hook into the Objective-C runtime and XCTest callbacks) is inspired by the implementation of the Quick testing framework.
How to review
There are two commits; one to provide the functionality and another to add an example parameterized test case. I’d suggest looking at the example and the documentation for ParameterizedTestCase before looking at the implementation (if you even want to look at the implementation, that is; I don't think it's hugely important if you don't want to get into those weeds).
What does this do?
For our upcoming
NetworkConnectivityTests
, we want to run a predefined list of test cases for all of the faults currently known to the SDK test proxy server.On Android, we use JUnit’s
@Parameterized
functionality to do this. There isn’t a corresponding thing inXCTest
, so here we build one.The general approach (where to hook into the Objective-C runtime and
XCTest
callbacks) is inspired by the implementation of the Quick testing framework.How to review
There are two commits; one to provide the functionality and another to add an example parameterized test case. I’d suggest looking at the example and the documentation for
ParameterizedTestCase
before looking at the implementation (if you even want to look at the implementation, that is; I don't think it's hugely important if you don't want to get into those weeds).An example of a parameterized test in action
Running all the tests in a file
https://user-images.githubusercontent.com/53756884/222514148-aabf10f1-bf3e-4a84-b238-1f73ca2eec8b.mov
Running a single test
You need to first of all run all the tests in the file to make Xcode aware of the test, then you can re-run it individually:
https://user-images.githubusercontent.com/53756884/222514599-28c1aec4-1f1a-4c90-b31d-87d1c9dc2fa0.mov