【发布时间】:2019-09-04 21:13:50
【问题描述】:
谁能解释一下这两个平台之间的区别吗?
都是BDD 的一部分,但我为什么要使用一个或另一个,或同时使用两者?
【问题讨论】:
标签: testing rubygems cucumber capybara bdd
谁能解释一下这两个平台之间的区别吗?
都是BDD 的一部分,但我为什么要使用一个或另一个,或同时使用两者?
【问题讨论】:
标签: testing rubygems cucumber capybara 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: 在代码 sn-p 中也有一些 RSpec。这是必需的,因为 Cucumber 或 Capybara 本身无法测试某些东西。他们依靠 RSpec、Test::Unit 或 minitest 来完成实际的“通过或失败”工作。
【讨论】:
cucumber 是一个 BDD 工具,它以业务可读的特定领域语言表达测试场景。
capybara 是一种用于 ROR 应用程序的自动化测试工具(经常使用)。
在 capybara github 页面上,using capybara with cucumber 上有一个示例。
【讨论】:
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) | |
|-------------------------------|-------------------------------|
【讨论】:
Capybara is itself a wrapper around selenium-webdriver stackoverflow.com/questions/45893060/….