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
未完待续。。。
相关文章推荐
- Mycat从入门到放弃
- DOCKER 从入门到放弃(三)
- JavaWeb从入门到放弃(3)-让外网能访问以及互传json
- Python从入门到放弃(一):概论
- 文件 Python从入门到放弃
- Realm数据库 从入门到“放弃”
- 推送 从入门到放弃
- 转-Android插件化:从入门到放弃
- Kotlin从入门到放弃(三)——协程
- React Native从入门到放弃之环境搭建
- 如何学习嵌入式? 嵌入式之路从入门到放弃....
- html从入门到放弃(3)-链接<a/>
- 30 分钟 git 命令入门到放弃
- html从入门到放弃(6)-入门标签:列表-有序、无序和自定义
- 《Java从入门到放弃》JavaSE入门篇:单元测试
- 转-Vue.js2.0从入门到放弃---入门实例(一)
- 《Java从入门到放弃》入门篇:使用注解的方式配置hibernate映射关系
- 翻身的废鱼——论PHP从入门到放弃需要多久?8
- GO 从入门开始放弃
- php从入门到放弃系列-01.php环境的搭建