README.md in xcfit-3.1.7 vs README.md in xcfit-4.0.0

- old
+ new

@@ -3,62 +3,64 @@ [![License](https://img.shields.io/cocoapods/l/XCFit.svg?style=flat)](http://cocoapods.org/pods/XCFit) [![Platform](https://img.shields.io/cocoapods/p/XCFit.svg?style=flat)](http://cocoapods.org/pods/XCFit) # XCFit : Full Stack iOS BDD in Xcode -**XCFit a.k.a ([XCUI](https://developer.apple.com/videos/play/wwdc2015/406/0), [Cucumberish](https://github.com/Ahmed-Ali/Cucumberish) and [Fitnesse](https://github.com/paulstringer/OCSlimProject) Integrations Tests) is a full stack Xcode BDD framework for [Swift](https://swift.org) iOS apps. XCFit allows us to write BDD Style API/Contract level, UI and Acceptance Tests with Swift in human readable language using tools like [Cucumber](https://cucumber.io/) and [Fitnesse](http://fitnesse.org/) in Xcode. We can still use Apple's brand new UI Testing framework (XCUI) under the hood of XCFit and Cucumberish. XCFit is fully automated solution for Cucumberish and Fitnesse. You can use 80(Fitnesse):20(Cucumberish) formula to automate Acceptance and UI Testing for better coverage and faster feedback. XCFit is available on [Homebrew](http://brew.sh), [RubyGem](https://rubygems.org/gems/xcfit), [CocoaPods](http://cocoadocs.org/docsets/XCFit), Carthage and Swift Package Manager.** +**XCFit a.k.a ([XCUI](https://developer.apple.com/videos/play/wwdc2015/406/0), [Cucumberish](https://github.com/Ahmed-Ali/Cucumberish) and [Fitnesse](https://github.com/paulstringer/OCSlimProject) Integration Tests) is a full stack Xcode BDD framework for iOS apps written in [Swift](https://swift.org). XCFit allows us to write BDD Style API/Contract level, UI and Acceptance Tests with Swift in human readable language using tools like [Cucumber](https://cucumber.io/) and [Fitnesse](http://fitnesse.org/) in Xcode. We can still use Apple's brand new UI Testing framework (XCUI) under the hood of XCFit and Cucumberish. XCFit provides automated Xcode templates to setup skeleton of BDD which are available on [Homebrew](http://brew.sh), [RubyGem](https://rubygems.org/gems/xcfit). XCFit also packaged asSwift Framework to provide pre-defined BDD Steps written in Swift. XCFit Swift framework is available on [CocoaPods](http://cocoadocs.org/docsets/XCFit), Carthage and Swift Package Manager.** ### XCFit -* [XCFit : Full Stack BDD in Xcode](#xcfit--full-stack-bdd-in-xcode) +* [XCFit : Full Stack iOS BDD in Xcode](#xcfit--full-stack-bdd-in-xcode) * [XCFit Features](#xcfit-features) * [Tech & Software Requirements](#tech--software-requirements) * [Installation](#installation) * [XCFit Swift Framework](#xcfit-swift-framework--xcui-page-object-pattern--pre-defined-steps) * [Setting Cucumberish BDD Scenarios in Xcode](#setting-cucumberish-bdd-scenarios-in-xcode) + * [Advide on using pre-defined BDD Steps](#advise-on-using-pre-defines-bdd-style-steps) * [Fitnesse for iOS: Acceptance/Contract Tests](#fitnesse-for-ios-acceptancecontract-tests) * [Continuous Integration with Xcode Server](#continuous-integration-with-xcode-server) * [XCFit: Swift Package Manager](#xcfit-swift-package-manager) * [Quick Demo with Example App](#quick-demo-with-example-app) + * [Step By Step Video Demo](#step-by-step-video-demo) * [Acknowledgements](#acknowledgements) * [Author](#author) * [TODO](#todo) * [LICENSE](#license) * [Contributing](#contributing) # XCFit Features *** - You can now write Given When Then (Gherkin), Predefined BDD Steps and Decision Table in Xcode. In Short, you can do BDD in Xcode for your iOS app. - - You can now write/Execute all your Acceptance Tests and UI Tests using Apple's brand new programming language "Swift" in Xcode. Goodbye Appium, Calabash, Frank, KIF and Goodbye Ruby,Java, Python. It's pure Swift !! + - XCFit supports Swift so no need to use other languages like Ruby, Java, Python to write acceptance and UI tests for iOS. - XCFit provides automated Xcode Target Templates for Cucumberish, Fitnesse and Page Object Pattern(XCUI) targets which reduce hectic Xcode configuration steps. It also arrange code in Xcode groups. - - XCFit will setup Xcode Template with skeleton code and provide BDD Style Steps with Swift Framework which is available on Cocoapods, Carthage and Swift Package Manager. + - XCFit will setup Xcode Templates with skeleton code and provide BDD Style Steps with Swift Framework which is available on Cocoapods, Carthage and Swift Package Manager. - ### XCFIT Templates & Related Frameworks + ### XCFIT & Other Frameworks * **XCFit Swift Framework with Pre-defined BDD Steps and Page Object Pattern Templates** XCFit setup [Page Object Pattern](http://martinfowler.com/bliki/PageObject.html) for Apple's [XCUI Test](https://developer.apple.com/videos/play/wwdc2015/406/) using 'XCUI POM Test Bundle' Templates. We can get pre-defined BDD steps by using XCFit Swift Framework from [CocoaPods](http://cocoadocs.org/docsets/XCFit), Carthage and Swift Package Manager. - * **Cucumberish BDD Framework and Cucucmber Style Xcode Templates** + * **Cucumberish BDD Framework and Cucucmber Style Xcode Templates(Optional Objective-C)** XCFit setup [Cucumber](https://cucumber.io) style BDD framework with "[Cucumberish](https://github.com/Ahmed-Ali/Cucumberish) UI Test Bundle' Templates. - * **Fitnesse Acceptance Tests for iOS using OCSlim Project** + * **Fitnesse Acceptance Tests for iOS using OCSlim Project (Optional Objective-C)** XCFit allows us to setup [Fitnesse](http://fitnesse.org/) style decision table test framework with [OCSlimProject](https://github.com/paulstringer/OCSlimProject) using 'Acceptance Tests Bundle' templates. ### Where to get XCFit -##### XCFit Swift Framework +#### XCFit Swift Framework * **CocoaPods** -- [XCFit-CocoaPods](http://cocoadocs.org/docsets/XCFit) : XCFit Swift Frameworks and BDD Style predefined steps for the iOS App. * **Carthage** -- You can install XCFit Swift Framework with Carthage as well for iOS Projects * **Swift Package Manager** -- Swift Package Manager doesn't support iOS projects yet but XCFit is compatible with Swift Package manager as well. -##### XCFit Templates +#### XCFit Templates * **Homebrew** - We can tap 'shashikant86/homebrew-taps' and Install XCFit to download Xcode Templates * **RubyGems** -- [xcfit-RubyGem](https://rubygems.org/gems/xcfit) to get automated Xcode Templates @@ -74,20 +76,18 @@ **Software** * **[Xcode 8.3](https://developer.apple.com/xcode/)** - - Ideally Xcode 8 but works on Xcode 7 as well. + - XCFit only Supports Xcode 8.3 and above. * **[Swift 3.1](https://swift.org/download/)** - - Use Swift 3.1-dev snapshot and toolchain. + - Use Swift 3.1-dev snapshot and toolchain. Swift 3.1 is currenly in beta. * **[Ruby](https://www.ruby-lang.org/en/)** - - Use [RVM](https://rvm.io/) for GEM management. Ideally Ruby > 2.X. You can use system Ruby with sudo + - Ruby is required to setup XCFit templates either using Homebrew or Rubygem. Use [RVM](https://rvm.io/) for GEM management. Ideally Ruby > 2.X. You can use system Ruby with sudo. * **[Curl on Mac](https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/curl.1.html)** - Might be pre-installed but worth double checking. * **[Homebrew](http://brew.sh)** -* **RubyGems Packages(optional)** - - Xcpretty, Fastlane(Optional), Rake, Bundler etc * **Fitnesse only Optional** : You might need to have [iOS-Sim](https://www.npmjs.com/package/ios-sim), [Java](https://www.java.com/en/) if you want to use Fitnesse. --- @@ -98,60 +98,60 @@ * **Xcode Template Installation** -This will install Xcode Templates with skeleton code to support BDD in iOS app. The templates are XCUI Page Object Templates, Cucumberish BDD Templated and OCSlim Fitnesse Templates. The templates can be installed with [xcfit-RubyGem](https://rubygems.org/gems/xcfit) or [Homebrew](http://brew.sh). +This will install Xcode Templates with skeleton code to support BDD in iOS app. The templates are XCUI Page Object Templates, Cucumberish BDD Templates and OCSlim Fitnesse Templates (optional). The templates can be installed with [xcfit-RubyGem](https://rubygems.org/gems/xcfit) or [Homebrew](http://brew.sh). You need to select only one method of installtion. * **Framework Installation** -XCFit Swift Framework provided pre-defined BDD Style steps with XCUI and supporting Frameworks like Cucumberish and OCSlim used to write BDD Steps. XCFit Swift Framework is available on [XCFit-CocoaPods](http://cocoadocs.org/docsets/XCFit), Carthage and Swift Package manager. [Cucumberish](https://github.com/Ahmed-Ali/Cucumberish) and [OCSlimProject](https://github.com/paulstringer/OCSlimProject) are available on Cocoapods. +XCFit Swift Framework provides pre-defined BDD Style steps with XCUI and supporting Frameworks like Cucumberish and OCSlim which cab be used to write BDD Steps. XCFit Swift Framework is available on [XCFit-CocoaPods](http://cocoadocs.org/docsets/XCFit), Carthage and Swift Package manager. [Cucumberish](https://github.com/Ahmed-Ali/Cucumberish) and [OCSlimProject](https://github.com/paulstringer/OCSlimProject) are available on Cocoapods. - -XCFit can be installed using [Homebrew](http://brew.sh) or using [RubyGems](https://rubygems.org/). - ## Template Installation XCFit templates can be installed using Homebrew or Rubygem. #### Homebrew Installation Assuming you have already installed [Homebrew](http://brew.sh). Let's tap the formula - brew tap shashikant86/homebrew-taps + $ brew tap shashikant86/homebrew-taps + Now, we can install XCFit brew package using - brew install xcfit + $ brew install xcfit -This will download XCFit templates. +This will download XCFit templates in the '~/Library/Developer/Xcode/Templates/' directory. #### XCFit RubyGem Installation -If you can't use HomeBrew for some reason then XCFit can be installed using [RubyGems](https://rubygems.org/). This will set our Xcode for BDD +If you can't use HomeBrew for some reason then XCFit can be installed using [RubyGems](https://rubygems.org/). This will set our Xcode with BDD templates for XCFit and Cucumberish + $ gem install xcfit You need to use with 'sudo' if you are using system (pre-installed) Ruby(2.0). XCFit gem will be used to set all the Xcode Templates for Xcode. You can choose any of the above method. Rubygems method is prefered. ### Setup Xcode Templates In existing app or brand new app, we have to enable the Xcode templates for targets to speed up the things. -##### Xcode 8 +##### Xcode Templates for XCFit + To setup Templates for Xcode 8 for XCUI, Cucumberish target and Gherkin File Type. ```sh $ xcfit setup_xcode_templates ``` -To Setup Fitnesse Templates +To Setup Fitnesse Templates (Optional) ``` $ xcfit setup_fitnesse_templates ``` @@ -161,11 +161,11 @@ ![image](https://github.com/Shashikant86/XCFit-GIFS/blob/master/Xcode8-Templates.png) ## Framework Installation -XCFit, Cucumberish or OCSlimProject Framework can be installed using Cocoapods. XCFit and Cuucmberish can be installed using Carthage as well +XCFit, Cucumberish or OCSlimProject Framework can be installed using Cocoapods. XCFit and Cuucmberish can be installed using Carthage as well. ### Cocoapods Cocoapods is more automated than Carthage. We can create `Podfile` and add specific dependency for the target ```ruby @@ -207,11 +207,12 @@ ) ``` Now we can use fetch XCFit using $ swift package fetch - We can build, test package using the commnds avavilable for the Swift Package Manager. + +We can build, test package using the commnds avavilable for the Swift Package Manager. --- # XCFit Swift Framework : XCUI Page Object Pattern + Pre-Defined Steps @@ -225,17 +226,21 @@ - Now Select 'XCFit' for iOS app and Click on 'XCUI POM Test Bundle' - Once Clicked on the target e.g 'XCUI POM Test Bundle' Xcode will create UI testing target with properly structured Xcode Groups and required files. You can then make physical directories on Disk Or change the folder/group structure as per your need. +- You may want to delete autogenerated UI test from Apple's standard template. + - You don't have to so any setting to run those demo XCUI tests. Just CMD+U and You are good to go ! + + ![image](https://github.com/Shashikant86/xcfitgif/blob/master/XCFitPOM_Templates.gif) ### What's in the XCUI POM Template ? -* **YOUR_CUCUMBERISH_TARGETPageObjectTests.swift** +* **YOUR_APP_TARGETPageObjectTests.swift** This file is at the base of the target. It's exactly same file that Apple's XCUI Test generate at first. You may use it for recording the tests or simply delete it if not needed. * **Screens** @@ -251,51 +256,64 @@ Testbase is group where we can abstract all setup, teardown and common stuff in the base class. Every Screen then use this class as base. You can add more stuff as needed e.g Fixtures, Launch Arguments ## Getting XCFit Framework for pre-defined BDD Style steps ### Cocoapods -You can get XCFit Framework eaily. Create `Podfile` and add specific dependency for the target +You can get XCFit Framework easily. Create `Podfile` and add specific dependency for the target ```ruby target '$_YOUR__TARGET' do pod 'XCFit' end ``` -Same way we can get 'Cucumberish' and 'OCSlim' for the specific target. +Now that, We need to install the framework using ```sh $ pod install ``` + Close existing Xcode Session and Open `.xcworkspace/`. Now in the 'testBase' class just `import XCFit` and extend the class to `XCFit` class. The predefined steps are ready to use. + ![image](https://github.com/Shashikant86/xcfitgif/blob/master/Pod_install_XCFit.gif) ### Carthage -If you are using Carthage then it's easy to install XCFit. Add following to `Cartfile` +It's easy to install XCFit using Carthage as well. Add following to `Cartfile` github "Shashikant86/XCFit" + Now fetch dependency and build XCFit using. + $ carthage update --platform iOS - This will create 'Carthage' directory with built framework. We need to manually drag and drop this to our XCUIPoMTest' target build settings. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk. On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script in which you specify your shell (ex: bin/sh), add the following contents to the script area below the shell: + + +This will create 'Carthage' directory with built framework. We need to manually drag and drop this to our XCUIPoMTest' target build settings. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk. On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script in which you specify your shell (ex: bin/sh), add the following contents to the script area below the shell: + /usr/local/bin/carthage copy-frameworks + and add the paths to the frameworks you want to use under “Input Files”, e.g.: + $(SRCROOT)/Carthage/Build/iOS/XCFit.framework + Here is Carthage looks like + ![image](https://github.com/Shashikant86/xcfitgif/blob/master/XCFit_Carthage.gif) You can choose any of the above method but Cocoapods is easy and less manual. -### Import XCFit & Use Predefined Steps +## Import XCFit & Use Predefined Steps -There are some predefined XCFit steps we can use by importing `XCFit` and extending out test base class to `XCFit`. Your test will read something like this: +There are some predefined XCFit steps we can use by importing `XCFit` and extending out test base class to `XCFit`. There are plenty of Pre-Defined BDD Style Stpes available [here](https://github.com/Shashikant86/XCFit/blob/master/Pre-Defined_Steps/XCFit_Predefined_Steps.md). You can use prefined steps wherever they make sense however it's fairly esasy to write your own. +Your test will read something like this: + ``` import XCTest import XCFit class XCFitTests: XCFit { @@ -317,11 +335,14 @@ ``` -You will get access to lots of predefined BDD style human redable steps. It's not mandatory to use those steps unless you wish. +You will get access to lots of predefined BDD style human redable steps. It's not mandatory to use those steps unless you wish. + +**Don't like Pre-defined steps, you can easily override the steps, covered in the later section [here](#advise-on-using-pre-defines-bdd-style-steps)** + ![image](https://github.com/Shashikant86/xcfitgif/blob/master/pre-defined_xcfit_steps.gif) --- @@ -333,27 +354,28 @@ - Now Select 'XCFit' for iOS app and Click on 'Cucumberish UI Test Bundle' - Once Clicked on the target e.g 'Cucumberish UI Test Bundle' Xcode will create UI testing target with all the required files with Bridging header for Cucumberish UI Testing. It create Page Object Pattern with all required files with screens, steps definitions and Cucumberish initialiser swift file. +Let's see what is inside the Cucumberish templates. ### What's in the Cucumberish Template ? * **YOUR_CUCUMBERISH_TARGET.swift** This file is at the base of the target. This initiate Cucumberish for project. We need to register all step definitions in this file. * **Screens** -This is groups where we can abstract logic of every screen in the app. Example file are 'HomeScreen.swift' and 'BaseScreen.swift' +This is groups where we can abstract logic of every screen in the app. Example file are 'HomeScreen.swift'. * **Step_Definitions** This groups has all the step definitions related to screen. Example file 'HomeScreenSteps.swift'. Once implemented we need to register it in the initialiser file mentioned above. * **Common** -This group has common code like extensions and common steps. The example file 'CommonStepDefinitions.swift' has some steps that can be used in the feature file. It also has 'Hooks.swift' to ad cucumber hooks. +This group has common code like extensions and common steps. The example file 'CommonStepDefinitions.swift' has some steps that can be used in the feature file. * **Supporting Files** This groups all the Objective-C headers and Bridging headers needed to get Cucumberish working with Swift. @@ -378,12 +400,16 @@ - Now Drag and Drop 'Features' directory to Xcode Cucumberish target - Select only '**Create folder references**' Option. ** Do Not Select 'Create groups' Or 'Copy items if needed**' -Now, We have to get cucumberish framework either using Carthage or Cocoapods. Let's doscuss both methods here +Now, We have to get cucumberish framework either using Carthage or Cocoapods. +## Get Cucumberish Framework + +Cucumberish is one of the dependency of XCFit so you will get Cucumberish with XCFit while using it with Cocoapods however Carthage need more setup. + ### Getting Cucumberish CocoaPod into our Target In order to get [Cucumberish](https://github.com/Ahmed-Ali/Cucumberish/tree/master/Cucumberish) source content. There are few ways we can do that - **Cocoapods** @@ -407,11 +433,11 @@ We now have everything we needed to run demo Cucumber demo test. Update Scheme if don't want to run unit test or other type of tests. and press 'CMD+U' ![image](https://github.com/Shashikant86/xcfitgif/blob/master/cucumberish_template.gif) -Congratulations !! You have just ran your first Cucumber BDD Scenario in the Xcode. Now add your own :) +Congratulations !! You have just ran your first Cucumber BDD Scenario in the Xcode. #### Create Separate Scheme if needed XCFit adds 'Cucumberish' target to existing Scheme. You can remove that target and run separate scheme to keep it independent from Unit tests. Make sure you make the new scheme executable for Running. @@ -432,11 +458,50 @@ Once drag and drop is don and we have "Features" directory then we are ready to launch our BDD Style tests using 'CMD+U'. The entire Carthage Setup looks like this ![image](https://github.com/Shashikant86/xcfitgif/blob/master/CarthageCucumberish.gif) +## Cucumberish Pre-Defined Steps +There are some pre-defined Cucumberish Steps available to use directly without any need to implement in the step definition. You can see list of steps [here](https://github.com/Shashikant86/XCFit/blob/master/Pre-Defined_Steps/Cucumberish_Predefined_Steps.md). You already have those steps in the 'CommonStepDefinitions.swift' file. You can modify the steps as per your project need or add your own. +**Don't like Pre-defined steps, you can easily override the steps, covered in the later section [here](#advise-on-using-pre-defines-bdd-style-steps)** + +# Advise on using Pre-Defines BDD Style Steps + +XCFit has pre-defined steps for both XCFit Swift framework as well as Cucumberish framework. + +* **[XCFit Pre-Defined BDD Style Steps](https://github.com/Shashikant86/XCFit/blob/master/Pre-Defined_Steps/XCFit_Predefined_Steps.md)** +* **[Cucumberish Pre-Defined BDD Style Steps](https://github.com/Shashikant86/XCFit/blob/master/Pre-Defined_Steps/Cucumberish_Predefined_Steps.md)** + +It's recommended to use your own steps as predefined steps might not read well for your project needs. Pre-defined steps gives you guidance on how to implement your own step, however you can use pre-defined steps wherever they make sense to avoid duplication. + +## Extending Predefined Steps. + +You can easily override pre-defined BDD Style Steps by writing Swift Extensions and Changing Common step definitions in the Cucumberish 'CommonStepDefinitions.swift' file. + +### Extending BDD Step from XCFit Framework + +XCFit has a step **`givenILaunchedApplication()`** and you are not happy about the wordings. You can easily write and Extension and your steps like this : + +``` + +extension XCFit { + + func givenMyiOSApplicationHasBeenLaunched() { + XCUIApplication().launch() + } + +} +``` + +Now you can use your own **`givenMyiOSApplicationHasBeenLaunched()`** step anywhere inside the Test target. + +### Extending/Changing Cucumberish BDD Steps + +XCFit template for setting Cucumberish has the Swift code for the all [pre-defined Cucumberish BDD Steps](https://github.com/Shashikant86/XCFit/blob/master/Pre-Defined_Steps/Cucumberish_Predefined_Steps.md) inside the **'CommonStepDefinitions.swift'** file. You just need to add your own steps accordingly or change the exiasting one. + + --- # Fitnesse for iOS: Acceptance/Contract Tests @@ -554,18 +619,26 @@ # Quick Demo with Example App You can clone the existing repo which has a demo app we can run Unit, Fitnesse and Cucumbertish Tests as XCTest - ``` - $ git clone https://github.com/Shashikant86/XCFit - $ cd XCFit/XCFit4Demo - $ open XCFit4Demo.xcodeproj/ - ``` - Run XCUI and Cucumberish test with Xcode. "cmd + U". You can script it with `xcodebuild` or Fastlane Tools. + $ git clone https://github.com/Shashikant86/XCFit + $ cd XCFit/XCFit4Demo + $ open XCFit4Demo.xcworkspace/ + + Run XCUI and Cucumberish test with Xcode using **'XCFit4Demo'** Scheme, press "cmd + U". You can also use "**AcceptanceUnitTests"** target/scheme and press "CMD+U" to run fitnesse tests. You can script it with `xcodebuild` or Fastlane Tools. + + + +# Step by Step Video Demo + +You can watch step by step video demo on Youtube. Click the link below + + [![Alt text](https://img.youtube.com/vi/7gqPxy6UVRw/0.jpg)](https://www.youtube.com/watch?v=7gqPxy6UVRw) + # Acknowledgements Big Thanks to - [Cucumberish](https://github.com/Ahmed-Ali/Cucumberish) : Provide native [Gherkin](https://github.com/cucumber/cucumber/wiki/Gherkin) parser for iOS Apps to enable BDD in Xcode using Given When Then. Yay! - [OCSlimProject](https://github.com/paulstringer/OCSlimProject) : Provide Xcode Templates to enable BDD with Decision Tables using Fitnesse @@ -577,10 +650,10 @@ # TODO * Add More Step Definitions for Cucumberish Projects * Improve Swift Package with additional XCUI test helpers - * Setting up XCFit on Apple's own CI Xcode Server + # LICENSE Copyright © 2014 Shashikant Jagtap, http://shashikantjagtap.net