1. Cucumber
Cucumber is a tool that can execute plain-text documents as automated functional tests. Here is an example:
Feature: Search courses In order to ensure better utilization of courses Potential students should be able to search for courses Scenario: Search by topic Given there are 240 courses which do not have the topic "biology" And there are 3 courses A,B,C that each have "biology" as one of the topics When I search for "biology" Then I should see the following courses: | title | | A | | B | | C |
用Cucumber来写客户验收测试的目的是明显的,就是让客户或者业务分析师能看懂甚至由他们来编写客户验收测试。
但在实际应用中,Cucumber真的能做到它想做的么?我个人是持怀疑态度的。理由有几点:
a. Cucumber测试用例的编写没有那么简单和自由。Cucumber的本质是在文本和程序语言之间建立一种映射。这种映射限制了cucumber测试用 例的编写必须遵循某种规则,并且每个语句都需要有相应的程序语言实现。那么就是说,如果要让客户或者业务分析师脱离开发或者测试人员,独立并且无障碍地编 写测试用例,我觉得大多数人没有这个能力。既然如此,它已经脱离了它本身的初衷。
b. 用method chain本身就可以实现基本类似的测试用例,为什么要多此一举呢?在项目中,我们用了cucumber,实践证明cucumber用例的编写和维护是相当麻烦的。
c. 大多数业务人员或者客户根本不会看它一眼。实践表明,大多数业务人员或者客户根本不会看它一眼。他们更相信手工测试的结果,即使是测试人员也是如此。
所以,不推荐用这个东西。
2. RSpec
RSpec is the original Behaviour Driven Development framework for Ruby.
Spec::Rails : A Rails plugin that brings RSpec to Rails.
3. spec_helper
# use transactional for each test. config.use_transactional_fixtures = true # not only insert yaml data to database, but also created all objects. But we always disable it # because of performance issue. config.use_instantiated_fixtures = false # default fixtures path config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
4. rspec describe
rspec测试中的describe XXXController有什么作用?看了源代码后,用这种方式会使这个spec成文被测试类的子类。那么它其中的public方法你都可以尽情调用。
5. integrate_views
对于rspec controller测试,在必要的地方加上integrate_views,否则页面上的错误将被忽视。
比如,你想验证在某种条件下,页面上会出现某些text,可以用这种方法:
response.should include_text("")
6. rspec pending test
describe "test some thing" do it "do some something" # it's a pending test with no implementation end