testing & QA

Cucumberish - BDD testing framework for iOS applications + sample application.

A Software Tester at Novoda who does his best to deliver highest quality iOS and Android applications.

Recently, I had the opportunity to collaborate on a project where we decided to change the way we work and apply Behaviour Driven Development practices into our mobile teams. Project team used that methodology not only in the way we were cooperating and communicating but also to drive our tests. I was responsible for finding the solution that would help with implementation of UI automated tests for iOS application. In this post you can find out what approach and tools team decided to use. What is more, you can check out the iOS app I built with the BDD testing framework and run some automated UI tests.

What is Behaviour Driven Development?

There are plenty of books that explain that methodology fully but I would like to express what it means to me in a few words. Personally, I find BDD as an agile methodology that focuses on the collaboration and communication between business and development teams. Its main goal is to create a shared understanding of what is expected from the application's behaviour and also to align business requirements with the code. In order to reach that point the team needs to speak a common language. Fortunately, there are various tools on the market that help to achieve that.

What is Cucumberish?

Cucumberish is the test automation framework that drives execution of the tests specified in feature files and written in Gherkin language.The framework integrates well with newest versions of Xcode and the implementation of the tests can be written in both Objective-C or Swift.

Why Cucumberish? There are other tools as well!

While I was doing some investigation on the possible tools we could use to automate our UI tests in connection with BDD approach I came across these:

  • Calabash - was always my first thought when talking about BDD on iOS until I found this article. It turns out that Xamarin, creator of Calabash, has decided to not to support and maintain the framework after iOS 11. The main reason is that the market's focus is on the native frameworks such as XCUITest or Espresso for Android.

  • Gherkin XCTest - the second tool I found was Gherkin XCTest framework. To be honest, I have not tried it out. The main reason behind that is the lack of support for tagging on feature and scenario levels. Tags allow you to organise your test suite and select which specific test scenarios you want to run. Lack of that important functionality couldn't allow me to use it.

How does Cucumberish work?

Tests are written in the .feature files in accordance with the best practices of the Gherkin syntax.

Example Scenario:

Scenario: Ability to tap on buy button
    Given user launches the application
    When user fills in all the text fields
    Then user is able to tap on buy button

When the steps of the scenario are ready. Each of the steps are implemented individually.

Example of a step implementation:

Then("user is able to tap on buy button") { _,_ in
        self.verifyBuyButtonIsHittable()
    }

func verifyBuyButtonIsHittable() {
        let buyNowButton = application.buttons["BuyNowBtn"]
        XCTAssertTrue(buyNowButton.isHittable)
    }

When running the tests, Cucumberish creates an XC test suite for each feature and an XCTestCase for each scenario and maps the steps with the code implemented for individual step.

How to add Cucumberish to your app project?

The creator of the framework suggests a few ways of adding Cucumberish to your project:

From my experience, I can say that the manual steps always made my setup successful. Setup via Cocoapods doesn’t create Objective-C bridging header file that is necessary to run tests whereas manual setup provide with that information.

Additionally, I would also recommend to everyone who wants to run their tests on physical devices to disable bitcode. Otherwise Xcode main complain about it and tests won’t be executed.

I normally set it up in Podfile by adding this:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ENABLE_BITCODE'] = 'NO'
        end
    end
end

Sample app

For the purpose of this blog post and Udemy's iOS course that I follow, I have built sample MiraclePill app together with the Cucumberish framework. Feel free to check it out and see how the UI tests have been implemented.

To run the tests:

  1. Run pod install in your project directory.
  2. Open xcworkspace file.
  3. Select MiraclePillUITests target.
  4. Select device or simulator from the list.
  5. Run cmd+u.
  6. 🎉

Sum up

I found Cucumberish framework very friendly to work with. It is easy to debug tests that are failing. What makes it great is also the fact that tests are written in human readable language. It means that every one without technical skills will be able to understand what features of the application are covered with automated tests.

I hope Cucumberish will be supported and maintained especially given that the future of the, so far, very popular Calabash framework is unknown.

Happy testing!

Enjoyed this article? There's more...

We send out a small, valuable newsletter with the best stories, app design & development resources every month.

No spam, no giving your data away, unsubscribe anytime.

About Novoda

We plan, design, and develop the world’s most desirable software products. Our team’s expertise helps brands like Sony, Motorola, Tesco, Channel4, BBC, and News Corp build fully customized Android devices or simply make their mobile experiences the best on the market. Since 2008, our full in-house teams work from London, Liverpool, Berlin, Barcelona, and NYC.

Let’s get in contact