DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Continuous Integration for iOS and macOS: Low-Code Self-Hosted Runner for Xcode Project Automation
  • Why I Prefer Flutter Over React Native for App Development
  • 6 of the Best API Testing Tools in the Market
  • Managing Technical Debt in Mobile Applications

Trending

  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Automatic Code Transformation With OpenRewrite
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Data Quality: A Novel Perspective for 2025
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. XCFit: Full Stack BDD for Swift Using XCUI, Cucumberish, and Fitnesse

XCFit: Full Stack BDD for Swift Using XCUI, Cucumberish, and Fitnesse

Shashikant Jagtap takes us through the features and usage of XCFit, which can be used to enable BDD for iOS and macOS using Swift.

By 
Shashikant Jagtap user avatar
Shashikant Jagtap
·
Jul. 25, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
11.2K Views

Join the DZone community and get the full member experience.

Join For Free

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!!
  • You can now write/Execute all your Acdeptance 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 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 Cucumberish Setup in one command.
  • Enhanced OCSlimProject templates and automated Fitnesse download process.
  • XCFit target templates are independent of native Xcode Test targets.
  • We can stiil use Apple’s brand new XCUI Testing framework. Its native Xcode implementation, No Appium, Calabash, etc., etc.
  • Setup Cucumberish and Fitnesse in Xcode within few minutes!!

Quick Demo With Example App

You can clone the existing repo which has a demo app. To get started. Watch this animated GIF for the steps below:

image

$ git clone https://github.com/Shashikant86/XCFit$ cdXCFit/XCFitDemo$ openXCFitDemo.xcworkspace

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.

$ xcodebuild -workspace XCFitDemo.xcworkspace -scheme XCFitDemo -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.3'test| xcpretty -r html -r junit --test--color

Watch out HTML and JUnit reports generated in the ‘Build/reports/’ directory with XCPretty. Install XCpretty if you haven't got it already.

Running Fitnesse Tests: Clean, Build, and Execute.

$ xcodebuild -workspace XCFitDemo.xcworkspace -scheme XCFitAcceptanceTests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.3'clean build | xcpretty   $java -jar fitnesse-standalone.jar -v-o -c "FrontPage?suite&format=junit"

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.

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 : 0.1.0

RubyGems — xcfit-RubyGem : 0.8.0

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.
  • Ruby Packages : Xcpretty, Fastlane(Optional), Rake, Bundler. Install with ‘gem install ‘

Installation

XCFit requires RubyGems to run.

You need RubyGem 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 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:

image

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.

imageYou can watch YouTube video of XCFit setup here.

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 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.

Feature: Demo App Feature   Scenario: Demo Scenario   Given the app isrunning

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!!

You can watch YouTube video of Cucumberish Setup here.

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.

image

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:

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 generated 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 running. Follow Paul’s article for the details on how to write acceptance tests here.

You can watch YouTube video of XCFit Fitnesse here.

image

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:

image

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 XCFitDemo.xcworkspace -scheme XCFitDemo -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6'test| xcpretty -r html -r junit --test--color

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.

$ open build/reports/tests.html

image

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. 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.

Source Code : GitHub

Full Stack BDD for iOS and macOS Apps with Swift, Xcode using XCUITest, Cucumberish, FitNesse and friends.

https://github.com/Shashikant86/XCFit

0 forks.
0 open issues.
Recent commits:

  • Update README.md, GitHub
  • Adding Test CLI argument to Fitnesse, Shashikant86
  • Enabling Fitnesse Tests on TravisCI, Shashikant86
  • Enabling Fitnesse Tests on TravisCI, Shashikant86
  • Sharing Scheme for TravisCI, Shashikant86

Video Demo

XCFit Xcode Setup

IMAGE ALT TEXT HERE

XCFit Cucumberish Demo

IMAGE ALT TEXT HERE

XCFit Fitnesse Demo

IMAGE ALT TEXT HERE

Let me know what you think about XCFit. Create an issue on GitHub if you want more info.

FitNesse unit test Swift (programming language) XCode mobile app Continuous Integration/Deployment Directory Template Question answering

Published at DZone with permission of Shashikant Jagtap, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Continuous Integration for iOS and macOS: Low-Code Self-Hosted Runner for Xcode Project Automation
  • Why I Prefer Flutter Over React Native for App Development
  • 6 of the Best API Testing Tools in the Market
  • Managing Technical Debt in Mobile Applications

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: