- Notifications
You must be signed in to change notification settings - Fork2
SwiftDocOrg/TAP
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Swift package for theTest Anything Protocol (v13).
- Swift 5.3+
You can useTAP
as an alternative toXCTest
in executable targetsor as a custom reporter in test targets.
import TAPtryTAP.run([test(1+1==2), // passestest(true==false) // fails])// Prints:/*TAP version 131..2ok 1not ok 2 --- file: path/to/File.swift line: 5 ... */
Swift Package Manager on Linuxusesswift-corelibs-xctest,which provides anXCTMain
that
Run the following commandon macOS to (re)-generate your main test file:
$ swift test --generate-linuxmain
Open the resultingLinuxMain.swift
file,add an import statement for theTAP
moduleand registerXCTestTAPObserver
as a test observer.In Swift 5.4 and later,you can update theXCTMain
invocation to include anobservers
parameterwith an instance ofXCTestTAPObserver
.
#if os(Linux)import XCTestimport TAP@testableimport TAPTests#if swift(>=5.4)XCTMain([testCase(TAPTests.allTests)],arguments:CommandLine.arguments,observers:[XCTestTAPObserver()])#elseXCTestObservationCenter.shared.addTestObserver(XCTestTAPObserver())XCTMain([testCase(TAPTests.allTests)])#endif
When you run theswift test
command,your test suite will be reported in TAP format.
As of Swift 5.3,it's not possible to configure a custom reporterwhen running tests directly through Swift Package Manager.However, Xcode provides a mechanism for loading custom reports viaXCTestObservationCenter
.
Create a new file namedTestObservation.swift
and add it to your test bundle.Import theTAP
module,declare a subclass ofNSObject
namedTestObservation
,and override its designated initializerto registerXCTestTAPObserver
with the sharedXCTestObservationCenter
.
import TAPfinalclassTestObservation:NSObject{overrideinit(){XCTestObservationCenter.shared.addTestObserver(XCTestTAPObserver())}}
Add an entry to your test target'sInfo.plist
filedesignating the fully-qualified name of this class as theNSPrincipalClass
.
<key>NSPrincipalClass</key> <string>YourTestTarget.TestObservation</string>
When you run your test bundle,Xcode will instantiate the principle class first,ensuring that your test observers are registered in timeto report the progress of all test runs.
Add the TAP package to your target dependencies inPackage.swift
:
import PackageDescriptionletpackage=Package( name:"YourProject", dependencies:[.package( url:"https://github.com/SwiftDocOrg/TAP", from:"0.2.0"),])
AddTAP
as a dependency to your test target(s):
targets:[.testTarget( name:"YourTestTarget", dependencies:["TAP"]),
MIT
Mattt (@mattt)
About
A Swift package for the Test Anything Protocol (v13)
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.