What is Swift Testing?
Swift Testing is a new testing framework for Swift. It works on Apple platforms as well as Windows and Linux. Anywhere Swift can be compiled Swift Testing can run.
Enabling XML Output
Swift testing has built in XUnit XML reporting support. When you run your tests from the command line add --xunit-output report.xml
to output an XML report to a file. Ex:
1import Testing23@Test func helloworld() {4 let greeting = "hello, world!"5 #expect(greeting == "hello, worldz!")6}
1swift test --xunit-output report.xml
1<?xml version="1.0" encoding="UTF-8"?>2<testsuites>3 <testsuite name="TestResults" errors="0" tests="1" failures="1" time="0.001664833">4 <testcase classname="MyCLITests" name="helloworld()" time="0.000832083">5 <failure message="Expectation failed: (greeting → "hello, world!") == "hello, worldz!"" />6 </testcase>7 </testsuite>8</testsuites>9
Test Suite naming
The format of Swift Testing's XML output is intended to match XCTests, which does not support changing test names using the @Suite
and @Test
description parameters. However, Swift Testing is in the process of building a more flexible, JSON-based output mechanism which includes, among other data, the display names for tests. For more information about this feature see this issue.