您的位置:首页 > 其它

cucumber从入门到放弃

2018-02-19 00:31 369 查看

Cucumber 从入门到放弃

建立一个存放project的文件夹: mkdir my-first-project
,个人建议先建立一个cucumber-test文件夹,之后的project都在这个文件夹下

在my-first-project目录下,初始化当前project: cucumber –init


在my-first-project目录下,执行cucumber

执行结果:

0 scenarios

0 steps

0m0.000s

在features目录下,创建feature文件

Feature: Adding
Scenario: Add two numbers
Given the input “2+2”
When the calculator is run
Then the output should be “4”


在my-first-project目录下,执行cucumber

执行结果:

Feature: Adding

Scenario: Add two numbers # features/adding.feature:2

Given the input “2+2” # features/adding.feature:3

When the calculator is run # features/adding.feature:4

Then the output should be “4” # features/adding.feature:5

1 scenario (1 undefined) 3 steps (3 undefined) 0m0.013s

You can implement step definitions for undefined steps with these

snippets:

Given(“the input {string}”) do |string| pending # Write code here

that turns the phrase above into concrete actions end

When(“the calculator is run”) do pending # Write code here that

turns the phrase above into concrete actions end

Then(“the output should be {string}”) do |string| pending # Write

code here that turns the phrase above into concrete actions end

运行cucumber命令时,会扫描features中的文件,每个feature中包含多个Scenario, Scenario中的step会调用step definitions中的编写的测试代码,以上错误,就是因为step definitions中没有feature文件对应的定义代码

在step_definitions目录下创建一个ruby文件,内容如下:

Given(/^the input “([^”]*)”$/) do |input|

@input = input

end

When(/^the calculator is run$/) do

@output =
ruby features/support/calc.rb #{@input}


raise(‘Command failed’) unless $?.success?

end

Then(/^the output should be “([^”]*)”$/) do |expected_output|

puts @expected_output

未完待续。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: