Skip to content

Setup Cucumberish with Cocoapods (Swift)

Brentley Jones edited this page Aug 23, 2017 · 4 revisions
  1. Make sure Defines Module Build Setting is set to Yes for your test target: Define modules build setting set to Yes

  2. Go to your test target folder and create a subfolder. Let's call it Features.

  3. Add this folder to your test target in Xcode and choose Create folder references. Features Folder as Folder not a Group Inside this folder, you will create the .feature files which will contain your test features and scenarios.

  4. 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)
  5. Create a new Objective-C .m file

  6. Replace the contents of this file with the following:

            //Replace CucumberishExampleUITests with the name of your swift test target
            #import "CucumberishExampleUITests-Swift.h"
            void CucumberishInit()
                [CucumberishInitializer CucumberishSwiftInit];
  7. 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!

You can’t perform that action at this time.