Cucumber for iOS, tvOS and macOS

Describe it in Gherkin. Prove it in Swift.

CucumberSwift is a lightweight, Swift-only Cucumber implementation. Your .feature files run as XCTest tests, right alongside the rest of your suite in Xcode.

  • MIT licensed
  • iOS 13+
  • macOS 10.15+
  • tvOS 13+
Latest version (opens in a new tab)
Features/Checkout.feature
Feature: Checkout

  Scenario: Paying with a saved card
    Given I have 2 items in my cart
    When I pay with my saved card
    Then I see "Order placed"
CheckoutSteps.swift
#Given("I have {int} items in my cart") { (count: Int) in
    cart.fill(with: count)
}
#When("I pay with my saved card") {
    checkout.payWithSavedCard()
}
#Then("I see {string}") { (message: String) in
    XCTAssertEqual(banner.text, message)
}

How it works

From a sentence to a passing test in three steps

  1. Describe the behaviour

    Write scenarios in .feature files that product, QA and engineering can all read. Keywords are localised, so the Gherkin can be in your team's language.

  2. Match each step

    Match steps with macros, using Cucumber Expressions or regular expressions. The compiler checks each parameter's type. Turn on the macros (opens in a new tab) with a package trait.

  3. Run it with XCTest

    Scenarios run as ordinary tests. For each step without a definition, CucumberSwift prints a stub to paste into your step definitions.

What's included

Small on purpose

CucumberSwift was written to be easy to install and easy to use. It covers what a Swift team needs from Cucumber, and not much else.

  • Cucumber Expressions

    Step definitions use readable patterns like {int} and {string}, and you can add your own typed parameters.

  • Six hooks

    Six hooks run before and after each feature, scenario and step.

  • JSON reports

    CucumberSwift writes a Cucumber JSON report in real time while your tests run.

  • Localised Gherkin

    Every Gherkin language has its own keyword functions, such as ES_Dado for Spanish.

Install

Add it to your test target

In Xcode, choose File › Add Package Dependencies… and paste the repository URL. Or add it to Package.swift. Carthage is supported too.

Follow the step-by-step tutorial (opens in a new tab)

Swift Package Manager

Package.swift
dependencies: [
    .package(url: "https://github.com/cucumberswift/CucumberSwift",
             from: "6.0.0")
],
targets: [
    .testTarget(name: "AppTests",
                dependencies: ["CucumberSwift"])
]

Carthage

Cartfile
github "cucumberswift/CucumberSwift"
Terminal
carthage update && carthage build --platform iOS

Documentation

Read the docs

The docs follow the latest stable release. Each major version has its own docs. Pick a version from the menu next to each library. The samples are working projects for the latest release.

Latest stable

CucumberSwift (opens in a new tab)

The CucumberSwift docs have tutorials for SPM and Carthage, articles on step matching, hooks and reports, and the full API reference.

Companion libraryLatest stable

CucumberSwiftExpressions (opens in a new tab)

CucumberSwiftExpressions is the Cucumber Expressions parser behind step matching. Its docs show how to write custom parameters.

Xcode projectsFor the latest release

Sample projects (opens in a new tab)

These Xcode projects are built and tested against the latest CucumberSwift release. Start from one, or compare your setup with it.