Giter Club home page Giter Club logo

kucumberl's Introduction

Kucumberl

What is kucumberl?

A pure-erlang, open-source, implementation of Cucumber

Quick start

It's easy

$ git clone https://github.com/openshine/kucumberl
$ cd kucumberl
$ make

And if you want to run the kucumberl examples...

$ make test

or (if you want to see examples with failures)

$ ./kucumberl

How can I use kucumberl in my erlang project?

You can copy the kucumberl binary generated when you excute 'make' to your project folder. kucumberl is a self-contained Erlang script.

How can I create my first test?

Copy the kucumberl script to your project folder

$ cp <kucumberl_folder>/kucumberl <myproject_folder>/

Create the test folders.

$ cd <myproject_folder>
$ mkdir -p tests/welcome/features/step_definitions

The folder structure is easy to explain

 $ tree
 .
 |-- kucumberl                     <- This is your kucumberl script
 `-- tests                         <- This is your test directory
    `-- welcome                    <- This is a directory to store a group of features to test
       `-- features                <- Here goes the feature's files. In other words, the test description.
          |-- step_definitions     <- Here goes the erl files.

Now, we go to create a new feature file to test the "welcome process" of our app. A feature file is a description of a scenario in plain text. The format of this file is really easy to read and write: Given a situation, When something, Then something... Please, put the next at ./tests/welcome/features/welcome_user.feature

Feature: Welcome user
  In order to check the welcome process
  As a new user
  I want to check the welcome service in this site

  Scenario: Hello my name is...
    Given I type my name, 'John'
    And I type my surname, 'Doe'
    When I press 'good welcome' button
    Then I see in the screen 'Hello, Mr John Doe'

If you save the feature file and execute ./kucumberl you will see something like that.

Feature: Welcome user
  Scenario: Hello my name is...
    Given I type my name, 'John'                                 Not implementated
    And I type my surname, 'Doe'                                 Not implementated
    When I press 'good welcome' button                           Not implementated
    Then I see in the screen 'Hello, Mr John Doe'                Not implementated

0 Scenario (0 failed, 0 passed)
4 Steps (0 failed, 0 passed, 0 skipped, 4 not implementated)

Yes, you have not implemented the test. This is the next step, you have to define in the steps_definitions directory what to do for each step (Given-When-Then). Now, please, put the next code at ./tests/welcome/features/step_definitions/welcome_user.erl

-module(welcome_user).
-export([setup/0, teardown/0, given/3, 'when'/3, then/3]).

-record(state, {name, surname}).

setup() -> #state{}.

given ("I type my name, '(\\w+)'", State, [Name]) ->
    %% Really complex testing code here! :P
    {ok, State#state{name = Name}};

given ("I type my surname, '(\\w+)'", State, [Surname]) ->
    %% Really complex testing code here! :P
    {ok, State#state{surname = Surname}}.

'when' ("I press 'good welcome' button", State, []) ->
    %% Do something :P
    {ok, State}.

then ("I see in the screen '(.+)'", State, [Str]) ->
    Name = State#state.name,
    Surname = State#state.surname,

    %% More complex testing code to generate the "hello" string :P
    GenStr = "Hello, Mr " ++ Name ++ " " ++ Surname,

    case Str =:= GenStr of
        true -> {ok, State};
	    false -> {failed, "Wow!"}
    end.

teardown() -> ok.

And now, execute ./kucumberl and you will see something like that.

$ ./kucumberl 
Feature: Welcome user
  Scenario: Hello my name is...
    Given I type my name, 'John'                                 OK
    And I type my surname, 'Doe'                                 OK
    When I press 'good welcome' button                           OK
    Then I see in the screen 'Hello, Mr John Doe'                OK

1 Scenario (0 failed, 1 passed)
4 Steps (0 failed, 4 passed, 0 skipped, 0 not implementated)

If you want to check more complex examples, go here.

Author

This is an openshine project developed by:

  • Roberto Majadas (roberto.majadas at openshine.com)

License

Copyright 2012 OpenShine S.L.

Licensed under the Apache License, Version 2.0

kucumberl's People

Contributors

telemaco avatar dieu avatar blt avatar

Watchers

James Cloos avatar Vinod Hegde 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.