Skip to content

XCTest Integration

Tyler Thompson edited this page Feb 4, 2021 · 6 revisions

It's important to understand that Cucumber simply provides a way to tie into Gherkin. CucumberSwift is coupled with XCode but does not require a specific kind of target. You can run it with a UI testing bundle, or a Unit testing bundle, whatever makes sense.

There have been a couple of instances where people have requested that CucumberSwift give a lot of the same control that you get with an XCTestCase so here we go:

Expectations

CucumberSwift defines a way to create expectations just like XCTestCase

Given("some precondition") { _, _ in
    let expectation = self.expectation(description: "waiting")
    self.wait(for: [expectation], timeout: 3)
}

ContinueAfterFailure

This can be a hot button topic, should a step stop executing as soon as it hits a failure, or should it keep going.

NOTE: This applies on a per-scenario basis. Because Scenario's are all designed to be independently executable. NOTE: After hooks will still be executed regardless of this setting

There are 2 ways of defining this:

Globally:
extension Cucumber: StepImplementation {
    public var continueTestingAfterFailure:Bool {
        return true
    }
}
Overridden by a step:
Given("some precondition") { _, step in //this ignores the global definition, but only for this step
    step.continueTestingAfterFailure = false
}