- 浏览: 2075996 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
Cucumber过去一年的测试热点和行为驱动开发的引导。
什么是Cucumber
Cucumber is known as an Acceptance Testing Framework. It’s part of Rspec’s testing tools. Aslak Hellesoy started it as an alternative to overcome the shortcomings of existing Rspec Story Runner. Cucumber allows you to write feature documentation in Plain Text. It means you could sit with your Client or Business Analyst to write down the features to be build on your application. Though Cucumber itself is written in Ruby, it can be used to test applications written in any language.
这样开始
Lets see how to use Cucumber, within the context of a Ruby On Rails application.
To get started, first install the Cucumber gem.
Also, we will require Webrat and Rspec(it’s not necessary, you could even use Test::Unit assertions)
Now move to your Rails application(or create a new one). Inside your Rails application directory run:
This will create a new directory called ‘features’ which includes Cucumber specific environment configurations and common set of steps(more on steps later)
添加测试部分
Centerpiece of Acceptance Testing is defining your features. It is recommended to do this process by hand, without using the generators.
For example, we need to add a admin section to manage users of our app. We could define this feature file(features/admin_dashboard.feature) in Cucumber, like this.
Header of the feature file is used to introduce the feature, what is its purpose, for whom it would matter and how it would be profitable for the business. There is no strict rule on what should be added in this section, you could add whatever you want in here. Define the tests in first-person. It will give you better focus and good understanding on how you would really use the feature.
After the header you have to define different scenarios of the feature. Each scenario consists of set of steps. A step must start with one of the following keywords - Given, When, Then, But or And. These steps allows you to structure your scenarios to a form which is easy to comprehend for anyone.
A step should have a definition which is written in Ruby. A step definition should consist a keyword, a string or regular expression, and a block. For example:
Above step definition, instructs Cucumber to fill in the Email field and submit the form. You could define steps as if a live user is interacting with the app. This has become possible thanks to Webrat. It allows you to fill in forms, follow links and scan for content within a page, as if it’s viewed via a web browser.
Further, you could attach hooks to your scenarios and steps. For example defining a ‘Before’ hook would ensure the code block is executed before each scenario.
执行定义测试步骤
To run all features in your app, in the command line enter rake features. If you need only a specific feature to be tested, run that feature file with cucumber command:
When a features are executed, it will show which the steps which are still pending, steps failed and steps skipped. Running features could also be used to grasp the status of a project. You will know how many features are still pending, which feature is currently in development and etc.
Give a try
I just covered only the basics of Cucumber. You will come to learn a lot when you give it a try. Especially, things such as how to use it with traditional unit testing and how to pace in the outside-in approach.
什么是Cucumber
Cucumber is known as an Acceptance Testing Framework. It’s part of Rspec’s testing tools. Aslak Hellesoy started it as an alternative to overcome the shortcomings of existing Rspec Story Runner. Cucumber allows you to write feature documentation in Plain Text. It means you could sit with your Client or Business Analyst to write down the features to be build on your application. Though Cucumber itself is written in Ruby, it can be used to test applications written in any language.
这样开始
Lets see how to use Cucumber, within the context of a Ruby On Rails application.
To get started, first install the Cucumber gem.
sudo gem install cucumber
Also, we will require Webrat and Rspec(it’s not necessary, you could even use Test::Unit assertions)
sudo gem install rspec rspec-rails webrat
Now move to your Rails application(or create a new one). Inside your Rails application directory run:
script/generate cucumber
This will create a new directory called ‘features’ which includes Cucumber specific environment configurations and common set of steps(more on steps later)
添加测试部分
Centerpiece of Acceptance Testing is defining your features. It is recommended to do this process by hand, without using the generators.
For example, we need to add a admin section to manage users of our app. We could define this feature file(features/admin_dashboard.feature) in Cucumber, like this.
引用
Feature: Admin Dashboard
In order to manage my users
As the admin of the app
I want to have an admin dashboard
Scenario: Listing All Users
Given I logged in as admin
When I visit users section
Then I should see all current users
Scenario: Editing a user
Given I logged in as admin
And there is a user called "Tom"
When I edit Toms email
Then I should see "Save successful!"
And I should see "newtom@example.com"
Scenario: Deleting a user
Given I logged in as admin
And there is a user called "Tom"
When I delete "Tom"
Then I should see "User was deleted."
And I should not see "Tom"
Scenario: Searching for a user
Given I logged in as admin
And there is a user called "Tom"
And there is a user called "Jerry"
When I search for "Tom"
Then I should see "Tom"
And I should not see "Jerry"
In order to manage my users
As the admin of the app
I want to have an admin dashboard
Scenario: Listing All Users
Given I logged in as admin
When I visit users section
Then I should see all current users
Scenario: Editing a user
Given I logged in as admin
And there is a user called "Tom"
When I edit Toms email
Then I should see "Save successful!"
And I should see "newtom@example.com"
Scenario: Deleting a user
Given I logged in as admin
And there is a user called "Tom"
When I delete "Tom"
Then I should see "User was deleted."
And I should not see "Tom"
Scenario: Searching for a user
Given I logged in as admin
And there is a user called "Tom"
And there is a user called "Jerry"
When I search for "Tom"
Then I should see "Tom"
And I should not see "Jerry"
Header of the feature file is used to introduce the feature, what is its purpose, for whom it would matter and how it would be profitable for the business. There is no strict rule on what should be added in this section, you could add whatever you want in here. Define the tests in first-person. It will give you better focus and good understanding on how you would really use the feature.
After the header you have to define different scenarios of the feature. Each scenario consists of set of steps. A step must start with one of the following keywords - Given, When, Then, But or And. These steps allows you to structure your scenarios to a form which is easy to comprehend for anyone.
A step should have a definition which is written in Ruby. A step definition should consist a keyword, a string or regular expression, and a block. For example:
When /^I edit Tom's email$/ do fill_in "Email", :with => "newuser@example.com" clicks_button "Update" end
Above step definition, instructs Cucumber to fill in the Email field and submit the form. You could define steps as if a live user is interacting with the app. This has become possible thanks to Webrat. It allows you to fill in forms, follow links and scan for content within a page, as if it’s viewed via a web browser.
Further, you could attach hooks to your scenarios and steps. For example defining a ‘Before’ hook would ensure the code block is executed before each scenario.
Before do @user = User.find_by_name("Tom") end
执行定义测试步骤
To run all features in your app, in the command line enter rake features. If you need only a specific feature to be tested, run that feature file with cucumber command:
cucumber features/admin_dashboard.feature
When a features are executed, it will show which the steps which are still pending, steps failed and steps skipped. Running features could also be used to grasp the status of a project. You will know how many features are still pending, which feature is currently in development and etc.
Give a try
I just covered only the basics of Cucumber. You will come to learn a lot when you give it a try. Especially, things such as how to use it with traditional unit testing and how to pace in the outside-in approach.
发表评论
-
Destroying a Postgres DB on Heroku
2013-04-24 10:58 935heroku pg:reset DATABASE -
VIM ctags setup ack
2012-04-17 22:13 3259reference ctags --extra=+f --e ... -
alias_method_chain方法在3.1以后的替代使用方式
2012-02-04 02:14 3295alias_method_chain() 是rails里的一个 ... -
一些快速解决的问题
2012-01-19 12:35 1472问题如下: 引用Could not open library ... -
API service 安全问题
2011-12-04 08:47 1386这是一个长期关注的课题 rest api Service的 ... -
Module方法调用好不好
2011-11-20 01:58 1349以前说,用module给class加singleton方法,和 ... -
一个ajax和rails交互的例子
2011-11-19 01:53 1908首先,这里用了一个,query信息解析的包,如下 https: ... -
Rails 返回hash给javascript
2011-11-19 01:43 2277这是一个特别的,不太正统的需求, 因为,大部分时候,ajax的 ... -
关于Rubymine
2011-11-18 23:21 2267开个帖子收集有关使用上的问题 前一段时间,看到半价就买了。想 ... -
ruby中和javascript中,动态方法的创建
2011-11-18 21:01 1241class Klass def hello(*args) ... -
textmate快捷键 汇总
2011-11-16 07:20 8147TextMate 列编辑模式 按住 Alt 键,用鼠标选择要 ... -
Ruby面试系列六,面试继续面试
2011-11-15 05:55 2025刚才受到打击了,充分报漏了自己基础不扎实,不肯向虎炮等兄弟学习 ... -
说说sharding
2011-11-13 00:53 1492这个东西一面试就有人 ... -
rails面试碎碎念
2011-11-12 23:51 1946面试继续面试 又有问ru ... -
最通常的git push reject 和non-fast forward是因为
2011-11-12 23:29 17216git push To git@github.com:use ... -
Rails 自身的many to many关系 self has_many
2011-11-12 01:43 2738简单点的 #注意外键在person上people: id ... -
Rails 3下的 in place editor edit in place
2011-11-12 01:20 946第一个版本 http://code.google.com/p ... -
Heroku 的诡异问题集合
2011-11-11 07:22 1697开个Post记录,在用heroku过程中的一些诡异问题和要注意 ... -
SCSS 和 SASS 和 HAML 和CoffeeScript
2011-11-07 07:52 12960Asset Pipeline 提供了内建 ... -
Invalid gemspec because of the date format in specification
2011-11-07 02:14 2122又是这个date format的错误。 上次出错忘了,记录下 ...
相关推荐
一个简单的入门项目,用于将Cucumber与量角器结合在一起。 该项目还有一个在测试中使用页面对象的示例。 工作中的新教程 该项目最近已更新为使用Cucumber.js版本2.3.1。 正在编写一个新教程,该教程将包含如何在最新...
一个用于在BrowserStack Automate上运行测试的示例项目。... 要运行测试,请执行: Cucumber会议笔记为Windows安装ruby *确保您...请访问 gem install cucumber gem install watir-webdriver cucumber --init将帮助您入门
魅力Cucumber-JVM示例 入门 要运行测试,您需要安装和 。 要生成“魅力报告”,您应该执行以下操作: 注意:必需的Maven版本3.1.1或更高版本 OnFailureSchedulerCallback 此功能使用户可以安排测试失败的事件。 ...
Serenity和Cucumber入门 Serenity BDD是一个库,可以轻松编写高质量的自动验收测试,并具有强大的报告和实时文档记录功能。 它对使用Selenium的Web测试和使用RestAssured的API测试都具有强大的支持。 Serenity强烈...
该项目提供了一个简单的入门示例,展示了如何设置和运行Cucumber测试。以下是关键知识点的详细说明: 1. **Gherkin语法**:Gherkin是一种业务领域特定的语言,用于编写用户故事和验收规范。在本示例中,你会找到`....
无服务器打字稿快速入门这是使用Serverless和Typescript构建API的快速入门示例 基础技术和框架-节点,无服务器,Express,打字稿,Cucumber要求节点8可用命令npm安装安装必需的依赖项,必须始终运行,然后其他任何...
在这个斐波那契计算器的示例中,可能的 Gherkin 场景可能包括: ```gherkin Feature: 斐波那契计算器 As a user I want to calculate Fibonacci numbers So that I can understand the sequence Scenario: 计算...
谷歌浏览器( ,用于默认配置的示例测试) Chrome WebDriver( ,将可执行文件放在您的本地路径中) Firefox( ,用于默认配置的示例测试)入门如果您想开始使用 SenBot,请使用我们的 Demo Archetype 创建一个新的 ...
例如,请在下面的示例配置中查看选项的完整列表: test_task: feature_order: ['features/featureOne', 'features/featureTwo', 'features/featureThree'] # These cucumber defaults will be set if not passed...
有很多在线资源和教程可以帮助你入门,例如官方文档、GitHub 上的示例项目,以及各种社区论坛。 总之,Cucumber 是 BDD 的强大工具,它通过将业务语言与实际代码关联起来,提高了团队沟通效率,确保软件符合用户...
一个简单的示例,说明如何将Capybara,Cucumber和Ruby结合在一起以自动执行Google Maps Search。 该项目使用Enrique Comba Riepenhausen在CukeUp 2013上提出的模仿者模式,请参见链接: ://skillsmatter....
### RSpec 入门者学习知识点详解 #### 一、RSpec 概述 RSpec 是一个流行的 Ruby 测试框架,主要用于行为驱动开发 (Behavior-Driven Development, BDD)。RSpec 的设计目的是让测试更加自然和易读,使得开发人员能够...
使用tzatziki生成的pdf报告的完整示例可以在此处找到 入门 Maven依赖 上次发布的版本: 0.16.0 对于pdf报告: <groupId>org.technbolts.tzatziki <artifactId>tzatziki-pdf ${tzatziki.version} 首先生成...
入门 使用 Eclipse IDE 或 IntelliJ,将源代码作为现有 Maven 项目导入。 先决条件 安装 - 仅对使用 CodeSV 模拟服务的 JUnit 测试需要。 安装 安装 、 或 执行测试 JUnit 测试 - 执行“mvn clean test” ...
入门 使用Eclipse IDE或IntelliJ,将源代码导入为现有Maven项目。 先决条件 安装 仅对于使用CodeSV模拟服务的JUnit测试是必需的。 安装 安装 , 或 执行测试 JUnit测试-执行“ MVN清除测试” 宁静BDD验收测试-...
这是在Java中使用Cucumber和Serenity BDD的非常小的示例项目。 您可以将此项目用作自己项目的快速入门。 有一个方案的一个功能部件文件。 该方案包含三个步骤,其中最后一个未决。 获取代码 Git: git clone ...
Serenity和Cucumber 6的REST API测试入门本教程向您展示如何使用Serenity和Cucumber 6进行REST-API测试。获取代码Git: git clone ...
程度Maven单元测试报告Cucumber报告Fitnesse报告BDD CucumberFitnesse 具有魅力的注解网络服务放心邮差肥皂界面新人网页界面Selenium宁静移动的机械人AppiumWindows 8/10应用Winimum示例赢8单元测试/
Kotlin进行组件测试的示例设置带有Spring合同测试示例的设置设置示例以使用Gatling进行性能测试使用Cucumber的BDD Framework示例设置入门指南安装首先克隆存储库git clone ... cd Kotlin-service-template mvn ...
此项目可作为API测试的一个示例,其中RestAssured和Java可以很好地配合使用。入门1. git clone https://github.com/sadabnepal/RestasssuredBDDFramework.git"2. Navigate to RestasssuredBDDFramework运行项目并...