有人能解释一下这两个平台的区别吗?
它们都属于BDD
,但为什么我应该使用一个还是另一个,或者两个都使用?
Capybara 是一个可以模拟人类访问网站的工具(如访问 URL、点击链接、在表单中输入文本并提交)。它用于模拟用户在网站上的操作流程。使用 Capybara,您可以编写以下代码:
describe "the signup process", :type => :feature do
before :each do
User.make(:email => 'user@example.com', :password => 'caplin')
end
it "signs me in" do
visit '/sessions/new'
within("#session") do
fill_in 'Login', :with => 'user@example.com'
fill_in 'Password', :with => 'password'
end
click_link 'Sign in'
page.should have_content 'Success'
end
end
黄瓜是一种工具,可用于编写映射到代码的可读性强的测试。使用它,您可以像这样重写上面的示例:
Scenario: Signup process
Given a user exists with email "user@example.com" and password "caplin"
When I try to login with "user@example.com" and "caplin"
Then I should be logged in successfully
这个近乎纯文本的解释有助于传达给非开发人员,但也需要一些代码与之配合才能实际工作(步骤定义)。
通常情况下,如果你正在测试一个网站,你会使用Capybara;如果你需要与非开发人员共享这些测试,则会使用Cucumber。这两个条件是独立的,因此你可以单独使用其中一个或两个或没有。
PS:在代码片段中还有一些RSpec。这是必需的,因为Cucumber或Capybara本身无法测试某些东西。它们依赖于RSpec、Test::Unit或minitest来完成实际的“通过或失败”工作。
黄瓜是一种BDD工具,用业务可读的领域特定语言表达测试场景。
Capybara是一个自动化测试工具(经常用于)ROR应用程序。
在Capybara的Github页面上,有一个关于如何使用Capybara和黄瓜的例子。
Cucumber是一种通用的BDD工具,它对Web应用程序一无所知。因此,Cucumber步骤定义调用Capybara来测试Web应用程序。
|-------------------------------|-------------------------------|
| Cucumber | Capybara |
|-------------------------------|-------------------------------|
| Test cases are more readable | Test cases are not readable; |
| and written in plain english | Capybara also wraps RSpec and |
| text as a DSL | you follow the same pattern to|
| | write test cases |
|-------------------------------|-------------------------------|
| Easy to iterate data using | Not easy to iterate data |
| tables | |
|-------------------------------|-------------------------------|
| Cucumber has its own runner | Uses RSpec runner to execute |
| | tests |
|-------------------------------|-------------------------------|
| Default HTML reporter | No default HTML reporter |
|-------------------------------|-------------------------------|
| Need to learn cucumber regex | No such concept |
| pattern to write step- | |
| definition which is the middle| |
| man for test case and script. | |
| Btw, the regex pattern is not | |
| essential for all cases. | |
|-------------------------------|-------------------------------|
| You can use the native | (Wrapper)/Built on top of |
| selenium-webdriver methods | selenium-webdriver ruby |
| while using Cucumber; Cucumber| library when used with |
| is just an additional | selenium; it can also be used |
| framework to your generic | with two other drivers. |
| automation framework | |
|-------------------------------|-------------------------------|
| Pure BDD framework (In theory | Traditional functional test |
| BDD sounds great. In practice,| model for end-to-end testing |
| product owners and developers | |
| rarely continue to use BDD) | |
|-------------------------------|-------------------------------|