Swift Testing

July 11, 2024

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.xmlto output an XML report to a file. Ex:

1import Testing
2
3@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 &#8594; &quot;hello, world!&quot;) == &quot;hello, worldz!&quot;" />
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.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users