swift-testing-revolutionary converts test cases written in XCTest to swift-testing
This tool provides three ways to use. As an Xcode Plugin, as a Command Plugin, or as a command line tool.
We provide three ways to use this tool.
Installation Methods | Good for | Convenience | Customization |
---|---|---|---|
Xcode Plugin | Xcode projects | ✅ | ❌ |
Package Command Plugin | Swift packages | ✅ | ✅ |
Command Line Tool | Any projects | ❌ | ✅ |
[!CAUTION] In default, all test files will be overwritten unless you passed
--dry-run
flag. Please make sure to backup your test files before running this tool.**
For Xcode project, it's better to use as a Xcode plugin.
RevolutionaryPlugin
.For Swift packages, it's better to use as a package plugin.
let package = Package(
name: "MyPackage",
dependencies: [
.package(url: "https://github.com/giginet/swift-testing-revolutionary", from: "0.1.0"),
]
)
You can pass the directories or files you want to convert.
$ swift package plugin --allow-writing-to-package-directory swift-testing-revolutionary Tests/ MyTests1.swift MyTests2.swift
Install this tool and run it from the command line.
$ swift-testing-revolutionary path/to/Tests
$ mint install giginet/swift-testing-revolutionary
experimental-install
$ git clone https://github.com/giginet/swift-testing-revolutionary
$ cd swift-testing-revolutionary
$ swift package experimental-install
Download swift-testing-revolutionary.artifactbundle.zip
from Releases and unzip it.
[!TIP] You can easily use artifactbundles with mtj0928/nest.
You can pass some options to the command.
Option | Description | Default |
---|---|---|
--dry-run | Run as a dry run mode. All test files are not overwritten | |
--enable/disable-struct-conversion | Whether converting test classes to structs or not | Enabled |
--enable/disable-strip-test-prefix | Whether stripping test prefix from each test method or not |
Enabled |
--enable/disable-adding-suite | Whether adding @Suite annotation to each test class or not |
Enabled |
In the default, all test classes would be converted to structs.
// Before
final class MyModelTests: XCTestCase { }
// After
@Suite struct MyModelTests { } // Enabled (Default)
@Suite final class MyModelTests { } // Disabled
If the test case contains tearDown
method. This tool always converts them to de-initializers.
However, deinit
can't be defined in the struct so this option should be passed for such cases.
In the default, all test methods would be stripped test
prefix.
// Before
func testProperty() { }
// After
@Test func property() { } // Enabled (Default)
@Test func testProperty() { } // Disabled
@Suite
In the default, all test classes would be annotated with @Suite
.
// Before
final class MyModelTests: XCTestCase { }
// After
@Suite struct MyModelTests { } // Enabled (Default)
struct MyModelTests { } // Disabled
See this article in swift-testing documentation.
Migrating a test from XCTest | Apple Developer Documentation
Currently, this tool supports following conversions referred above documentation.
import XCTest
)final class XXXTests: XCTestCase
)setUp
, tearDown
)func testXXX()
XCTAssert~
)XCTUnwrap
)XCTFail
)continueAfterFailure
)XCTExpectation
)XCTSkipIf
, XCTSkipUnless
)XCTExpectFailure
)Unsupported features have to be converted manually.
MIT License