My unit tests are divided into different subclasses of XCTestCase
.
For a specific initialization of the app I want to check if a unit test of a certain XCTestCase
subclass has been started.
Such a subclass is defined using
class SomeTestCase: XCTestCase { //… }
I know that I can check for the existence of XCTestCase
using
NSClassFromString("XCTestCase") != nil
This works. However,
NSClassFromString("SomeTestCase") != nil
does not work.
Why does this check not work for a subclass of XCTestCase
?
How could I check for its existence?
PS: I know I could set a launch argument in the scheme. But then I had to use different schemes for the different subclasses, which is not feasible.
I think the difference in behaviour is because SomeTestCase
is a Swift class and its class name will include the module in which it is defined.
If you use NSStringFromClass(SomeTestCase.self)
then you can see the name that is being used.
Alternatively, you can give the test class an explicit name to use in the Objective-C environment:
@objc(SomeTestCase)
class SomeTestCase: XCTestCase { //… }