Code Monkey home page Code Monkey logo

capriccio's Introduction

Capriccio

Swift 4.2 Build Status codecov

Capriccio is a tool to generate UI Tests from gherkins .feature files.

Capriccio generates test files using XCTest-Gherkin

An example of how it works

If you have a feature files like

Feature: Feature number one

Scenario: Scenario I want to  test
Given I'm in a situation
When something happens
Then something else happens

Scenario: Other scenario I want to  test
Given I'm in another situation
When something different happens
Then something else happens

It generates:

import XCTest
import XCTest_Gherkin

final class FeatureNumberOne: XCTestCase {
    func testScenarioIWantToTest() {
        Given("I'm in a situation")
        When("Something happens")
        Then("Something else happens")
    }

    func testOtherScenarioIWantToTest() {
        Given("I'm in another situation")
        When("Something different happens")
        Then("Something else happens")
    }
}

What is the benefit of using Capriccio?

Gherkin feature files can be easly shared between different platform. With Capriccio you to generate executable code from the feature files on a specific folder, all you have to do is run Capriccio as part of your build process (For example in a script phase).

Runtime vs Compile time

There a lot of different tools that allows to run tests from a feature files, like Cumberish or XCTest-Gherkin. But they generates the tests at runtime. By generating the tests at compile time you get some benefits:

  • You can use the navigator to see, inspect and re run the tests
  • You have a better integration with some CI services
  • You can actually see the generated test code

How to use it

to use it just run:

capriccio source destination <option>

source The path to the folder that contains the feature files destination The path to the folder where the swift files will be generated

Personalise setUp and tearDown

Your UI Tests will probably need to do something that is specific to your code base before and after every test. In order to allow Capriccio to support all this needs you can use the -c or --class-type option. This allows you to create a generic class that you can use as superclass for all the generated classes.

e.g.

class GherkinTestCase: XCTestCase {
    var mockedServer: MockedServer
    var stepDefinition: StepDefinitions!
    var application: App!

    override func setUp() {
        super.setUp()
        mockedServer = MockedServer()
        mockedServer.start()
        
        stepDefinition = StepDefinitions(testCase: self)

        application = App()
        application.launch()
    }

    override func tearDown() {
        mockedServer.stop()
        application.terminate()
        super.tearDown()
    }
}

Then if you run:

capriccio source destination -c GherkinTestCase

All the generated classes will be a subclass of GherkinTestCase instead of a subclass of XCTestCase

Scenario outline

Capriccio creates a different test for each example.

e.g.

Feature: Feature number one

Scenario Outline: Scenario I want to  test
Given I'm in a situation
When something happens <key1>
Then something else happens <key2>
Examples:
| key1 | key2 |
| value1 | value2 |
| value3 | value4 |

Generates:

import XCTest
import XCTest_Gherkin

final class FeatureNumberOne: XCTestCase {
    func testScenarioIWantToTestWithValue1AndValue2() {
        Given("I'm in a situation")
        When("Something happens value1")
        Then("Something else happens value2")
    }
        
    func testScenarioIWantToTestWithValue3AndValue4() {
        Given("I'm in a situation")
        When("Something happens value3")
        Then("Something else happens value4")
    }
}

capriccio's People

Contributors

f-meloni avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.