-
Notifications
You must be signed in to change notification settings - Fork 83
Setup Cucumberish with Cocoapods (Swift)
-
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 import Cucumberish public class CucumberishInitializer: NSObject { public 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]; }
-
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 good to go!