XCTestSuite+QuickTestSuiteBuilder.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import <XCTest/XCTest.h>
  2. #import <objc/runtime.h>
  3. #if __has_include("Quick-Swift.h")
  4. #import "Quick-Swift.h"
  5. #else
  6. #import <Quick/Quick-Swift.h>
  7. #endif
  8. @interface XCTestSuite (QuickTestSuiteBuilder)
  9. @end
  10. @implementation XCTestSuite (QuickTestSuiteBuilder)
  11. /**
  12. In order to ensure we can correctly build dynamic test suites, we need to
  13. replace some of the default test suite constructors.
  14. */
  15. + (void)load {
  16. Method testCaseWithName = class_getClassMethod(self, @selector(testSuiteForTestCaseWithName:));
  17. Method hooked_testCaseWithName = class_getClassMethod(self, @selector(qck_hooked_testSuiteForTestCaseWithName:));
  18. method_exchangeImplementations(testCaseWithName, hooked_testCaseWithName);
  19. }
  20. /**
  21. The `+testSuiteForTestCaseWithName:` method is called when a specific test case
  22. class is run from the Xcode test navigator. If the built test suite is `nil`,
  23. Xcode will not run any tests for that test case.
  24. Given if the following test case class is run from the Xcode test navigator:
  25. FooSpec
  26. testFoo
  27. testBar
  28. XCTest will invoke this once per test case, with test case names following this format:
  29. FooSpec/testFoo
  30. FooSpec/testBar
  31. */
  32. + (nullable instancetype)qck_hooked_testSuiteForTestCaseWithName:(nonnull NSString *)name {
  33. return [QuickTestSuite selectedTestSuiteForTestCaseWithName:name];
  34. }
  35. @end