You probably can't do it in pure swift since NSInvocation
is not part of swift api anymore.
XCTest rely on + (NSArray<NSInvocation *> *)testInvocations
function to get list of test methods inside one XCTestCase
class. Default implementation as you can assume just find all methods that starts with test
prefix and return them wrapped in NSInvocation
. (You could read more about NSInvocation
here)
So if we want to have tests declared in runtime, this is point of interest for us.
Unfortunately NSInvocation
is not part of swift api anymore and we cannot override this method.
If you OK to use little bit of ObjC then we can create super class that hide NSInvocation details inside and provide swift-friendly api for subclasses.