XCFit
XCFit a.k.a (XCUI, Cucumberish and Fitnesse Integrations Tests) is a full stack Xcode BDD framework for Swift iOS and macOS apps. XCFit allows us to write API, UI and Acceptance Tests in human readable language using tools like Cucumber and Fitnesse in Xcode. XCFit is fully automated solution for Cucumberish and Fitness. XCFit is available on RubyGem and CocoaPods.
XCFit Features
There are few reason you should go for XCFit
You can now write Given When Then and Decision Table in Xcode !! YAY.. Thanks to Cucumberish and OCSlimProject ! And XCFit automated them !!
XCfit provides Xcode Templates to create new Cucumberish and Fitnesse targets which reduce hectic Xcode configuration steps. It's all automated in XCfit
One command to set all fully automated Xcode template for Cucumberish and Fitnesse targets
New Template to create Gherkin Feature file in Xcode
Automated almost all Cucumberish Setup in one command
Enhanced OCSlimProject (https://github.com/paulstringer/OCSlimProject) templates and automated Fitnesse download process.
XCFit target templates are independent of native Xcode Test targets.
Its native Xcode implementation, No Appium, Calabash etc etc
Setup Cucumberish and Fitnesse in Xcode within few minutes !!
Big Thanks to
- Cucumberish : Provide native Gherkin parser for iOS Apps to enable BDD in Xcode using Given When Then. Yay!
- OCSlimProject : Provide Xcode Templates to enable BDD with Decision Tables using Fitnesse
XCFit automated configuration of these two guys.
Version
CocoaPods -- XCFit-CocoaPods : TBD
RubyGems -- xcfit-RubyGem : TBD
Tech & Software Requirements
XCFit uses a number of open source projects to work properly. You need to have following
Hardware : You must have Mac Operating System with OSX/MacOS version > 10.9
Software:
- Ruby - Use RVM for GEM management. Ideally Ruby > 2.X
- Xcode - Ideally Xcode 7.X
- RubyGems - RubyGem with Cocoapods installed
- Curl on Mac - Might be pre-installed but worth double checking.
Installation
XCFit requires RubyGems to run.
You need Gulp installed globally:
$ gem install xcfit
Now you are good to get started with XCFit for now. Later we also need to install XCFit Pod.
Usage
Now that you can execute 'xcfit' command from your terminal/iTerm etc etc. Example Output Looks like this :
$ xcfit
Tasks:
xcfit get_cucumberish VERSION # Downloads Cucumberish version and Create Features directory. You must execute this from Cucumberish Xcode Target directory
xcfit get_fitnesse # Download Fitnesse JAR file from Internet. You must execute this from Xcode Fitnesse Acceptance Test Xcode Target directory
xcfit help [TASK] # Describe available tasks or one specific task
xcfit set_xcode_templates # Generate All Xcode Templates for the Gherkin Feature Files & targets for Cucumberish and Fitnesse
xcfit version # Get the current version number
Setup Xcode Templates
In existing app or brand new app, we have to enable the Xcode templates for files and targets to speed up the things. Run following command from your termonal
$ xcfit set_xcode_templates
- This will add couple of templates to your Xcode for iOS and macOS apps. In your app if you go to 'File--->New--->Target'
You will see new option for iOS and OSX i.e 'XCFit'. Once Clicked on it. You will see Cucumberish API, Cucumberish UI and Fitnesse Acceptance Tests targets. As shown
Once Clicked on the target e.g 'Cucumberish UI Test Bundle' Xcode will create UI testing target with all the required files with Bridging hrader for Cucumberish UI Testing. Once Clicked on the target e.g 'Fitnesse Acceptance Test Bundle' Xcode will create UI tAcceptance test with all the required files with Bridging headers for the Fitnesse Acceptance Test. We will see that in details soon.
This script also set new file type in Xcode to create new Gherking feature file
Setting up Cucumberish UI Target
3 Steps to setup Cucumberish. You don't need to use Cocoapods to setup this target.
- Add new target iOS/macOS project and Select "File -> New -> Target -> XCFit -> Cucumberish UI Test Bundle". Give it a name you like e.g CucumberishUITests
Now that Xcode has created brand new target with all required Swift and Objective-C files to run Cucumberish. All Xcode setting has been done by the Xcode Template. Don't worry about configuting anything.
- Now that you have to CD into the Cucumberish target directory .eg CucumberishUITests
$ cd $CUCUMBERISH_TARGET_DIR
$ xcfit get_cucumberish 0.0.7
This will download Cucumberish directory from version 0.0.7 and also creats 'Features' directory with demo feature. You can then reference those directory in Xcode. For "Cucumberish" directory select 'Copy if needed and Create Group' and for the "Features" directory select don't create group or Copy if needed. Just " create folder reference"
- Finally from the Cucumberish target 'General' setting select 'Testing -> Target To Test' and configure scheme to add Cucumeerish UI target to Test
You are done !!
Setting up Fitnesse Acceptance Target
You can also setup Fitnesse Acceptance Tests but you need to use Cocoapod for this target.
Basically Steps are pretty much same mentioned in the OCSlimProject but most of them are automated for simplicity. Here is simple way to set Fitnesse Acceptance tests for iOS/MacOS Apps
Create new target, "File --> New --> Target --> XCFit --> Fitnesse Acceptance Test". Give it a suitable name e.g 'AcceptanceTests'
Create/Update Podfile with
use_frameworks!
target 'AcceptanceTests' do
pod 'XCFit'
end
Run 'Pod install' and build newly created Acceptance target from Xcode. You should see 'LaunchFitnesse' Script geerated and Your app should be talking to fitnesse now.
- Now CD into FITNESSE_TARGET directory and Get Fitnesse JAR file by running
$ cd $FITNESSE_TARGET
$ xcfit get_fitnesse
You should have fitnesse-standalone file downloaded in the target directory. You can now execute 'LaunchFitnesse'
$ ./LaunchFitnesse
Now you should have Fitnesse up and runnig. Follow Paul's article for the details on how to write acceptance tests here
Continous Integration & Test Reporting
As of now, you might be running tests within Xcode, but there are some awsome tools which allows us to run our tests from command line. The 'xcodebuild' is being used to build and test Xcode Schemes. Fastlane seems much easier option to automate everything but it's upto you. These are long commands but you k ow better how to Script it Or Fastlane it, right ? :)
Cucumberish
You can execute Cucumberish tests with like this for XCFitDemo App.
XCPretty can be used to generate JUnit Or HTML report as below
xcodebuild -workspace CuPod.xcworkspace -scheme CuPodUITests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.3' test | xcpretty --test --color
You can now analyse the reports generated in the 'build/reports' directory.
Fitnesse
You can first build the Acceptance target
$ xcodebuild -workspace XCFitDemo.xcworkspace -scheme XCFitAcceptanceTests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' clean build | xcpretty
Now run the Fitnesse tests using
$ java -jar fitnesse-standalone.jar -v -o -c "FrontPage?suite"
You can also set reports directory and generate Junit style reports inside the "XCFitDemo/FitNesseRoot/files/testResults/" directory.
Video Demo
Coming Soon !
Author
Shashikant86, [email protected]
License
XCFit is available under the MIT license. See the LICENSE file for more info.