idelfonsog2 / Cucumberish-UnitTest

Sample project building BDD using Ahmed-Ali/Cucumberish OSS pod for iOS Swift 4.2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install Instructions

These instructions were created from trial and error for the UnitTest Target

  1. Create a new Xcode project
  2. Include Unit Tests
  3. In your Podfile include Cucumberish in your Unit Tests Target
	use_frameworks!
	platform:ios, '11.0'

	target 'AppName' do
		use_frameworks!
	end

	target 'AppNameUnitTests' do
		inherit! :search_paths
		pod 'Cucumberish'
	end
  1. Run pod install

  2. In the navigation pane of your Xcode project: inside AppNameTests folder create a new objc header file and rename it to: AppNameTests-Bridging-Header.h and add the following line in the meantime: #import <Cucumberish/Cucumberish.h>

  3. In the navigation pane of your Xcode project: inside AppNameTests folder create a new objc implementation file and rename it to: CucumberishTest.m and add the following contents:

#import "AppNameUnitTests-Swift.h"

void CucumberishInit(void);

__attribute__((constructor))
void CucumberishInit()
{
    [CucumberishInitializer CucumberishSwiftInit];
}
  1. Navigate to the AppNameTests and add a new folder with name Features

Here you will create new empty files with the name of the feature follow by the .feature file extension as an example name it Login.feature

  1. Add a new swift file inside the folder AppNameTests and name it CucumberishInitializer.swift
  2. Inside CucumberishInitializer.swift add the following content:
import Foundation
import Cucumberish

@objc public class CucumberishInitializer: NSObject {
    @objc public class func CucumberishSwiftInit() {

        LoginSteps().LoginStepsImplementation()
        let bundle = Bundle(for: CucumberishInitializer.self)

        Cucumberish.executeFeatures(inDirectory: "Features", from: bundle, includeTags: nil, excludeTags: nil)
    }
}
  1. Create a new folder inside AppNameTests directory and name it StepDefinitions
  2. As an example create a new swift file a name it LoginStep.swift , which is where the actually Gherkin language is match with Regex
import Foundation
import Cucumberish

class LoginSteps: LoginScreen {

    func LoginStepsImplementation() {
        Given("I'm a new user that is registering for the first time") { args, dataTable in
            // call your unit test implementations
        }

        When("the user submits the registration form with the following details") { args, dataTable in
            // call your unit test implementations
        }

        Then("the user is successfully registered") { args, dataTable in
            // call your unit test implementations
        }
    }
}

import Foundation
@testable import TestCucumber

class LoginScreen: XCTestCase {
    func loginWithUsername(_ username: [String]) {
      XCTAssert(username.first! == "Idelfonso")
    }

}

  1. Run your UnitTest [CMD + U] and you will see the XCTest classes being generate it in the process. A simulator device needs to be selected

About

Sample project building BDD using Ahmed-Ali/Cucumberish OSS pod for iOS Swift 4.2


Languages

Language:Swift 80.9%Language:Objective-C 9.7%Language:Ruby 6.1%Language:Gherkin 3.2%