Giter Site home page Giter Site logo

lamtrinhdev / swift-testing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apple/swift-testing

0.0 0.0 0.0 1.94 MB

A modern, expressive testing package for Swift

License: Apache License 2.0

C++ 1.10% C 0.98% Swift 96.75% CMake 1.11% Dockerfile 0.05%

swift-testing's Introduction

Swift Testing

Swift Testing is a package with expressive and intuitive APIs that make testing your Swift code a breeze.

Feature overview

Clear, expressive API

Swift Testing has a clear and expressive API built using macros, so you can declare complex behaviors with a small amount of code. The #expect API uses Swift expressions and operators, and captures the evaluated values so you can quickly understand what went wrong when a test fails.

@Test func helloWorld() {
  let greeting = "Hello, world!"
  #expect(greeting == "Hello") // Expectation failed: (greeting → "Hello, world!") == "Hello"
}

Custom test behaviors

You can customize the behavior of tests or test suites using traits specified in your code. Traits can describe the runtime conditions for a test, like which device a test should run on, or limit a test to certain operating system versions. Traits can also help you use continuous integration effectively by specifying execution time limits for your tests.

@Test(.enabled(if: AppFeatures.isCommentingEnabled))
func videoCommenting() async throws {
    let video = try #require(await videoLibrary.video(named: "A Beach"))
    #expect(video.comments.contains("So picturesque!"))
}

Easy and flexible organization

Swift Testing provides many ways to keep your tests organized. Structure related tests using a hierarchy of groups and subgroups. Apply tags to flexibly manage, edit, and run tests with common characteristics across your test suite, like tests that target a specific device or use a specific module. You can also give tests a descriptive name so you know what they’re doing at a glance.

@Test("Check video metadata",
      .tags(.metadata))
func videoMetadata() {
    let video = Video(fileName: "By the Lake.mov")
    let expectedMetadata = Metadata(duration: .seconds(90))
    #expect(video.metadata == expectedMetadata)
}

Scalable coverage and execution

Parameterized tests help you run the same test over a sequence of values so you can write less code. And all tests integrate seamlessly with Swift Concurrency and run in parallel by default.

@Test("Continents mentioned in videos", arguments: [
    "A Beach",
    "By the Lake",
    "Camping in the Woods"
])
func mentionedContinents(videoName: String) async throws {
    let videoLibrary = try await VideoLibrary()
    let video = try #require(await videoLibrary.video(named: videoName))
    #expect(video.mentionedContinents.count <= 3)
}

Cross-platform support

Swift Testing works on all major platforms supported by Swift, including Apple platforms, Linux, and Windows, so your tests can behave more consistently when moving between platforms. It’s developed as open source and discussed on the Swift Forums so the very best ideas, from anywhere, can help shape the future of testing in Swift.

The table below describes the current level of support that Swift Testing has for various platforms:

Platform CI Status (6.0) CI Status (main) Support Status
macOS Build Status Build Status Supported
iOS Supported
watchOS Supported
tvOS Supported
visionOS Supported
Ubuntu 22.04 Build Status Build Status Supported
Windows Build Status Supported

Works with XCTest

If you already have tests written using XCTest, you can run them side-by-side with newer tests written using Swift Testing. This helps you migrate tests incrementally, at your own pace.

Documentation

Important

This package is under active, ongoing development and requires a recent 6.0 development snapshot toolchain. Its contents and interfaces are still considered experimental at this time and may change. See this Forum post for details about stable release plans.

Detailed documentation for Swift Testing can be found on the Swift Package Index. There, you can delve into comprehensive guides, tutorials, and API references to make the most out of this package. To try it yourself, see Getting Started.

Other documentation resources for this project can be found in the README of the Documentation/ subdirectory.

swift-testing's People

Contributors

grynspan avatar stmontgomery avatar dennisweissmann avatar medreisbach avatar ojun9 avatar briancroom avatar ejvaughan avatar shahmishal avatar compnerd avatar sajjon avatar finestructure avatar uhooi avatar elonpark avatar jeffdav avatar chuckdude avatar ahoppen avatar etcwilde avatar iamleeg avatar eltociear avatar weissi avatar kyle-ye avatar maxdesiatov avatar xedin avatar sandrodahl avatar u-abyss avatar wangxingyu5529 avatar

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.