Problem with --enable-test-discovery and the XCTestObservationCenter

Hi :wave:

I'm one of the creators of the swift-junit library. This library uses XCTestObservationCenter mechanism, in XCode it uses principal class, in Linux it uses LinuxMain.swift to register our class. The problem occurs when a developer uses the swift test --enable-test-discovery then there is no way to register a supervising class. Of course you can generate LinuxMain.swift with swift test --enable-test-discovery --generate-linuxmain then modify the generated file manually or with a shell script but this is an ugly solution. Do you have any other solution?

1 Like

Could you make the call to addTestObserver(_:) in setUp()?

open class MyTestSuperclass: XCTestCase {
  private static var initialized = false
  open override func setUp() {
    if !MyTestSuperclass.initialized {
      MyTestSuperclass.initialized = true
      addTestObserver(/* ... */)
final class SomeTests: MyTestSuperClass {
  func testThis() { /* ... */ }
final class OtherTests: MyTestSuperClass {
  func testThat() { /* ... */ }