有人可以解释这两个平台之间的区别吗?
都是其中的一部分,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
Cucumber是一种用于编写映射到代码中的人类可读测试的工具。有了它,你可以像这样重写上面的例子:
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 来完成实际的“通过或失败”工作。
Cucumber 是一个通用的 BDD 工具。它对网络应用一无所知。因此 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) | |
|-------------------------------|-------------------------------|