XCFit

Today, I am glad to announce “XCFit Framework” which can be used to enable BDD for iOS and macOS apps using Apple’s brand new programming language Swift and UI Testing framework. This project is inspired by Cucumberish and OCSlim project. Let’s see what are the features and usage of XCFit in this post. You can find official web page of XCFit on shashikant86.github.io.

XCFit – ‘Swift’ Your iOS/macOS Apps Towards BDD

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 with Swift in human readable language using tools like Cucumber and Fitnesse in Xcode. We can still use Apple’s brand new UI Testing framework (XCUI) under the hood of 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 RubyGem and CocoaPods.

XCFit Features

There are a few reasons 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!!

Run Unit, UI and Cucumberish test with Xcode. “cmd + U”. Edit Scheme, if nessesary, to avoid running Unit Tests for this demo. Or Run nit from command line. Update Simulator device/OS version as installed in your Xcode, if nessessary.

Installation

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 &amp; 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 the following command from your terminal:

$ 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 a new option for iOS and OSX i.e ‘XCFit’. Once clicked, 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.

Now that Xcode has created a 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 configuring 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. You can then reference those directories in Xcode. For the “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” Now Add sample Feature File to ‘Features’ directory either by File->New->Gherkin Or Just add it using your favourite text editor e.g demo.feature with content.

You can add more feature/Scenarios and implement steps definitions inside your Swift File. Ahmed-Ali creator of Cucumberish already implemented useful pre-defined steps have a look at this Swift file. You are free to try Page Object Pattern and all other crazy stuff to abstract and refactor your Swift code.

Setting up Fitnesse Acceptance Target

You can also setup Fitnesse Acceptance Tests but you need to use Cocoapod for this target.

Basically, the 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:

Continous Integration & Test Reporting

Continous Integration is very important and you simply can’t avoid that. XCFit will be easily configured on any CI server including Apple’s own Xcode Server or very popular one Jenkins as we can generate reports in both HTML and JUnit format. As of now, you might be running tests within Xcode, but there are some awsome tools which allow 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 up to you. These are long commands but you k ow better how to Script it Or Fastlane it, right ?

Currently, XCFitDemo App is configured on TravisCI which runs both Cucumberish and Fitnesse Tests. The sample .travis.yml is in the Github repo and sample logs from TravisCI here. Watch out Live Execution:

You can now analyse the reports generated in the ‘build/reports’ directory. You will find both HTML and JUnit reports. You can configure these reports with Xcode-Server, Jenkins, TeamCity easily in the post build setting.

You can also set reports directory and generate Junit style reports inside the “XCFitDemo/FitNesseRoot/files/testResults/” directory. You can configure these reports with Xcode-Server, Jenkins, TeamCity easily in the post build setting.

What XCFit Can Solve in iOS/macOS Team?

XCFit can bring lot of improvement the way you work. The most common problems in iOS development is explained by Paul Stringer in this article. XCFit can solve few of them:

Better Developer/QA collabration, Early QA Involvement.

Usually,in the iOS development world, Developer build an app using Swift and Objective-C and army of manual and automated QA uses tools like Apppium, Calabash using languages like Ruby, Java, Python WTF!!. QA and Developers world is totally different. With XCFit you will be speaking the same language that is “Swift”. QA can write test script as we build. No need to wait until build is handed over. Just work with developers! Little bit of learning curve for QA but you will save developers time as they don’t to learn Java, Python, or Ruby to help the QA team.

Quick Acceptance & UI Testing Setup

You will be surprised by how easily/quickly you can setup Fitnesse(Acceptance Test) and Cucumberish(UI Testing) environment in Xcode and running your first test.

Getting Business People Involved

As we can now able to write scenarios with Given/When/Then and decision tables. We can get business people involved to contribute to acceptance criteria. In short we got all benefits of BDD in iOS/macOS project.

Developers Don’t Need to Learn Ruby or Similar! Just Stick to Swift

You must be happy as you won’t need to learn other languages just in case QA ask something to solve. With XCFit it’s everything Swift.

Fix Failed Attempt to Automate Testing by QA Team

As of now your QA team might have tried all wrappers on UIAutomation, e.g. Appium, Calabash, Frank, KIF, etc., etc and keeping themselves busy writing some Ruby, Python, and Java code to automate testing and all that attempts results in Slow, Brittle, Untrusted, Non-valuable UI tests causing harm to mobile development rather than good. With XCFit, everyone will be speaking the same language and you can cover business logic with lighting fast Fitnesse Tests and major journeys with UI tests. Keep it 80:20 means 80% Fitness and 20% Cucumberish or XCUI.