黄瓜与水豚

时间:2013-02-21 14:36:43

标签: testing rubygems cucumber capybara bdd

有人可以解释这两个平台之间的差异吗? 是 BDD 的一部分,但为什么我应该使用一个或另一个,或两者兼而有之? 谢谢你的回答

4 个答案:

答案 0 :(得分:93)

Capybara 是一种以人类的方式与网站互动的工具(如访问网址,点击链接,在表单中输入文字并提交)。它用于模拟用户通过网站的流量。在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

几乎纯文本解释对于传递非开发人员很有用,但也需要映射到其中的一些代码才能实际工作(步骤定义)。

如果您正在测试网站并使用Cucumber,通常您将使用Capybara,如果您需要与非开发人员共享这些测试。这两个条件是独立的,因此您可以使用一个不使用另一个或两者或不使用。

PS:在代码段中也有一些RSpec。这是必要的,因为Cucumber或Capybara本身不能测试某些东西。他们依靠RSpec,Test :: Unit或minitest来完成实际的“通过或失败”工作。

答案 1 :(得分:5)

cucumber是一个BDD工具,它以业务可读,特定于域的语言表达测试场景。

capybara是ROR应用程序的自动化测试工具(经常使用)。

在capybara github页面上,using capybara with cucumber上有一个例子。

答案 2 :(得分:4)

Cucumber是一种通用的BDD工具。它对网络应用程序一无所知。因此,Cucumber步骤定义调用Capybara以测试Web应用程序。

答案 3 :(得分:0)

|-------------------------------|-------------------------------|
|      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)   |                               |
|-------------------------------|-------------------------------|