openshine/kucumberl

语言: Erlang

git: https://github.com/openshine/kucumberl

README.md (中文)

Kukumberl

  • 什么是Kucumberl?
  • 快速开始
  • 我怎样才能在我的erlang项目中使用kucumberl?
  • 我怎样才能创建我的第一个测试?
  • 作者
  • 执照

什么是kucumberl?

纯粹的erlang,开源,Cucumber的实现

快速开始

这很容易

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

如果你想运行kucumberl例子......

$ make test

或(如果你想看到失败的例子)

$ ./kucumberl

如何在我的erlang项目中使用kucumberl?

您可以将执行'make'时生成的kucumberl二进制文件复制到项目文件夹中。 kucumberl是一个独立的Erlang脚本。

我怎样才能创建我的第一个测试?

将kucumberl脚本复制到项目文件夹

$ cp <kucumberl_folder>/kucumberl <myproject_folder>/

创建测试文件夹。

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

文件夹结构很容易解释

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

现在,我们将创建一个新的功能文件来测试我们的应用程序的“欢迎过程”。 功能文件是纯文本方案的描述。这个文件的格式非常容易读写: 鉴于某种情况,当有什么事情,那么...... 请将下一个放在./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'

如果您保存要素文件并执行./kucumberl,您将看到类似的内容。

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)

是的,您尚未实施测试。 这是下一步,您必须在steps_definitions目录中定义每个步骤要执行的操作(Given-When-Then)。 现在,请将下一个代码放在./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.

现在,执行./kucumberl,你会看到类似的东西。

$ ./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)

如果您想查看更复杂的示例,请转到此处。

作者

这是一个由以下开发的openshine项目:   * Roberto Majadas(来自openshine.com的roberto.majadas)

执照

版权所有2012 OpenShine S.L.

根据Apache许可证2.0版获得许可

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

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