Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test xml.file is not generated #12

Open
derLalla opened this issue Nov 2, 2020 · 2 comments
Open

Test xml.file is not generated #12

derLalla opened this issue Nov 2, 2020 · 2 comments

Comments

@derLalla
Copy link

derLalla commented Nov 2, 2020

Hi, I am working on a Mac and I am building a plain Swift project (no Xcode project).
I've done all steps in the Readme (without the steps for Xcode, as it is no Xcode project) but no test.xml file is getting generated. What am I doing wrong or where can I find the generated junit xml-file?

I am doing the following:

swift build
Fetching https://github.com/alexaubry/HTMLString.git
Fetching https://github.com/allegro/swift-junit.git
Cloning https://github.com/alexaubry/HTMLString.git
Resolving https://github.com/alexaubry/HTMLString.git at 5.0.0
Cloning https://github.com/allegro/swift-junit.git
Resolving https://github.com/allegro/swift-junit.git at 2.0.0

swift test
...
Test Suite 'All tests' passed at 2020-11-02 14:52:15.834.
         Executed 2 tests, with 0 failures (0 unexpected) in 0.086 (0.086) seconds

This is my Package.swift:

// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "swiftExercise",
    dependencies: [
        .package(name: "SwiftTestReporter", url: "https://github.com/allegro/swift-junit.git", from: "2.0.0"),
    ],
    targets: [
        .target(name: "swiftExerciseLib"),
        .target(name: "swiftExerciseApp", dependencies: ["swiftExerciseLib"]),
        .testTarget(name: "swiftExerciseTests", dependencies: ["swiftExerciseLib", "SwiftTestReporter"]),
    ]
)

My Swift version: Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)

@ar4s
Copy link
Contributor

ar4s commented Nov 2, 2020

Please try to add following code:

class TestObserverTestCase: XCTestCase {
  private static var initialized = false

  open override func setUp() {
    if !TestObserverTestCase.initialized {
      TestObserverTestCase.initialized = true
      _ = TestObserver()
    }
    super.setUp()
  }
}

Then modify your tests, so as to inherit from this particular class, it should works.

@derLalla
Copy link
Author

derLalla commented Nov 11, 2020

Thanks, but I had to modify it a bit for it to work. This needs to be called before the very first test case is executed otherwise the first testcase is missing out in the resulting tests.xml.
So I've created a

/** 
  * This init class needs to be the first executed test case. 
  * It is needed to set the TestObserver once to create the tests.xml file on macOS
  * Class name starts with 'AA' to be the first executed test.
  */
class AA_InitTest: XCTestCase {
    override class func setUp() {
        _ = TestObserver()
        super.setUp()
    }

    // dummy test method to be interpreted as a test case
    func testInit() {}
}

This has to be the first executed test case and leads to all subsequent test cases being included in the tests.xml.

I also think that this approach wouldn't break the LinuxMain.swift, as the testInit() function is not included in the overall allTests variable. So I hope this won't get executed. Because setting _ = TestObserver() twice will lead to an double output of The file tests.xml was created in the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants