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

Skipped tests are not reported as skipped in xUnit output #7383

Closed
1 task done
adam-fowler opened this issue Feb 29, 2024 · 5 comments
Closed
1 task done

Skipped tests are not reported as skipped in xUnit output #7383

adam-fowler opened this issue Feb 29, 2024 · 5 comments
Assignees
Labels
bug swift test Changes impacting `swift test` tool

Comments

@adam-fowler
Copy link

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI.

Description

The xUnit file output by swift test --parallel --xunit-output <file> does not report when a test is skipped

Expected behavior

xUnit file has an xml node that indicates the test was skipped

Actual behavior

Instead it reports that the test ran as if it passed

Steps to reproduce

  1. In SwiftPM project create test with the first line try XCTSkipIf(true)
  2. Run swift test --parallel --xunit-output test.xml
  3. Inspect test.xml
    There is no indication in the file that test was skipped

Swift Package Manager version/commit hash

5.9.2

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Darwin Adams-MBP-M1-Max.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64

@grynspan grynspan self-assigned this Feb 29, 2024
@grynspan grynspan added the swift test Changes impacting `swift test` tool label Feb 29, 2024
@grynspan
Copy link
Contributor

I wish we had a proper JUnit XML schema to follow here. I think this is as close as we have to a spec: https://github.com/junit-team/junit5/blob/main/junit-platform-reporting/src/main/java/org/junit/platform/reporting/legacy/xml/XmlReportWriter.java

It does have "skipped" so we can do that.

@grynspan
Copy link
Contributor

XCTest will need to be taught to report a skipped test in a way Swift Package Manager can detect; that may ultimately need to wait until we teach XCTest how to produce JSON output like we do for Swift Testing, at which point a common implementation is possible.

grynspan added a commit to swiftlang/swift-testing that referenced this issue Jul 18, 2024
This PR adds skipped test reporting to our JUnit XML output. For example, given
this test:

```swift
@test(.disabled("Because I said so"))
func f() {}
```

The XML output would be, approximately:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="TestResults" errors="0" tests="1" failures="0" skipped="1" time="12345.0">
    <testcase classname="MyTests" name="f()" time="12344.0">
      <skipped>Because I said so</skipped>
    </testcase>
  </testsuite>
</testsuites>
```

See also swiftlang/swift-package-manager#7383 which
asks for this for XCTest.
grynspan added a commit to swiftlang/swift-testing that referenced this issue Jul 18, 2024
This PR adds skipped test reporting to our JUnit XML output. For
example, given this test:

```swift
@test(.disabled("Because I said so"))
func f() {}
```

The XML output would be, approximately:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="TestResults" errors="0" tests="1" failures="0" skipped="1" time="12345.0">
    <testcase classname="MyTests" name="f()" time="12344.0">
      <skipped>Because I said so</skipped>
    </testcase>
  </testsuite>
</testsuites>
```

See also swiftlang/swift-package-manager#7383
which asks for this for XCTest.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@adam-fowler
Copy link
Author

@plemarquand I don't know if you are following this

@grynspan
Copy link
Contributor

Currently, the XCTest implementation of xUnit (JUnit) XML output is based solely on the exit status of the process hosting each test. Additional information such as the cause of a failure is not available. Resolving this problem will require an overall refactoring of how XCTest produces its XML output. That work is tracked by #4752, so I'm going to mark this issue as a duplicate of that one.

@grynspan
Copy link
Contributor

Duplicate of #4752

@grynspan grynspan marked this as a duplicate of #4752 Jul 24, 2024
@grynspan grynspan closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug swift test Changes impacting `swift test` tool
Projects
None yet
Development

No branches or pull requests

2 participants