Coder Social home page Coder Social logo

tap's Introduction

TAP

A Swift package for the Test Anything Protocol (v13).

Requirements

  • Swift 5.3+

Usage

You can use TAP as an alternative to XCTest in executable targets or as a custom reporter in test targets.

Running Tests Directly

import TAP

try TAP.run([
    test(1 + 1 == 2), // passes
    test(true == false) // fails
])
// Prints:
/*
TAP version 13
1..2
ok 1
not ok 2
  ---
  file: path/to/File.swift
  line: 5
  ...
  
*/

Custom Test Reporting

Linux

Swift Package Manager on Linux uses swift-corelibs-xctest, which provides an XCTMain that

Run the following command on macOS to (re)-generate your main test file:

$ swift test --generate-linuxmain

Open the resulting LinuxMain.swift file, add an import statement for the TAP module and register XCTestTAPObserver as a test observer. In Swift 5.4 and later, you can update the XCTMain invocation to include an observers parameter with an instance of XCTestTAPObserver.

#if os(Linux)
import XCTest
import TAP
@testable import TAPTests

#if swift(>=5.4)
XCTMain([
    testCase(TAPTests.allTests)
],
arguments: CommandLine.arguments,
observers: [
    XCTestTAPObserver()
])
#else
XCTestObservationCenter.shared.addTestObserver(XCTestTAPObserver())
XCTMain([
    testCase(TAPTests.allTests)
])
#endif

When you run the swift test command, your test suite will be reported in TAP format.

macOS and iOS

As of Swift 5.3, it's not possible to configure a custom reporter when running tests directly through Swift Package Manager. However, Xcode provides a mechanism for loading custom reports via XCTestObservationCenter.

Create a new file named TestObservation.swift and add it to your test bundle. Import the TAP module, declare a subclass of NSObject named TestObservation, and override its designated initializer to register XCTestTAPObserver with the shared XCTestObservationCenter.

import TAP

final class TestObservation: NSObject {
    override init() {
        XCTestObservationCenter.shared.addTestObserver(XCTestTAPObserver())
    }
}

Add an entry to your test target's Info.plist file designating the fully-qualified name of this class as the NSPrincipalClass.

    <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 time to report the progress of all test runs.

Installation

Swift Package Manager

Add the TAP package to your target dependencies in Package.swift:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/SwiftDocOrg/TAP",
        from: "0.2.0"
    ),
  ]
)

Add TAP as a dependency to your test target(s):

targets: [
.testTarget(
    name: "YourTestTarget",
    dependencies: ["TAP"]),

License

MIT

Contact

Mattt (@mattt)

tap's People

Contributors

mattt avatar maxdesiatov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

r-a-o 0xleif

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.