-
Notifications
You must be signed in to change notification settings - Fork 83
Install manually for Swift
-
Add the Cucumberish folder to your test target. When prompted choose "Create groups".
-
Go to your test target build settings, and add the following preprocessor macro:
SRC_ROOT=@\"$(SRCROOT)\"
-
Make sure Defines Module Build Setting is set to Yes for your test target:
-
Go to your test target folder and create a subfolder. Let's call it Features.
-
Add this folder to your test target in Xcode and choose Create folder references. Inside this folder, you will create the .feature files which will contain your test features and scenarios.
-
Replace the content of the auto-created test case file with the following:
import Foundation class CucumberishInitializer: NSObject { class func CucumberishSwiftInit() { //Using XCUIApplication only available in XCUI test targets not the normal Unit test targets. var application : XCUIApplication! //A closure that will be executed only before executing any of your features beforeStart { () -> Void in //Any global initialization can go here } //A Given step definition Given("the app is running") { (args, userInfo) -> Void in } //Another step definition And("all data cleared") { (args, userInfo) -> Void in //Assume you defined an "I tap on \"(.*)\" button" step previousely, you can call it from your code as well. let testCase = userInfo?[kXCTestCaseKey] as? XCTestCase SStep(testCase, "I tap the \"Clear All Data\" button") } //Create a bundle for the folder that contains your "Features" folder. In this example, the CucumberishInitializer.swift file is in the same directory as the "Features" folder. let bundle = Bundle(for: CucumberishInitializer.self) Cucumberish.executeFeatures(inDirectory: "Features", from: bundle, includeTags: nil, excludeTags: nil) } }
-
Create a new Objective-C .m file
-
Replace the contents of this file with the following:
//Replace CucumberishExampleUITests with the name of your swift test target #import "CucumberishExampleUITests-Swift.h" __attribute__((constructor)) void CucumberishInit() { [CucumberishInitializer CucumberishSwiftInit]; }
-
Create a bridge file and name it (just an example) bridging-header.h and save it in the folder of that test target.
-
Open the test target Build Settings and set the value of "Objective-C Bridging Header" to be
${SRCROOT}/${TARGET_NAME}/bridging-header.h
-
In the bridge header you just created, add the following import:
#import "Cucumberish.h"
-
Only in case the name of folder that contains your test target files is different than the test target name, set the value of the Cucumberish property testTargetFolderName to the correct folder name before calling the execute method.
And you are ready to get started!