Capybara:  A complete reference is available atrubydoc.info.

集成测试就是把局部的程序组合起来测试。

端到端测试是一个特殊的集成测试,覆盖了系统的全部行为, end-to-end.

接受测试acceptance test是用来指定正确行为,从客户或商业想法出发。Acceptance tests 通常在代码开始之前就计划或者写了。

集成测试也使用Javascript driver来评测基于Javascript的模仿用户行动。

本章是无Js版本,下章是有Js版本。

  • Setting up Capybara✅
  • Using Feature Tests to bulid a Feature✅
  • What to Test in an RSpec System test✅
  • Outside-in Testing
  • Making the Capybara Test Pass
  • Retrospective回顾
  • Setting up Cucumber ⚠️新的知识点,概览!!
  • Writing Cucumber Features
  • Writing Cucumber Steps
  • Advanced Cucumber
  • is Cucumber Worth it?

A Field Guide to Integration and System Tests

Rails core testing library defines two similar types of end-to-end test:

integration test:传统的Rails测试,使用自己的API,功能没Capybara强大。

system test:5.1新增的。需要使用Capybara 。也叫feature tests. 也可以叫integration test。

另外Request 测试,是指URL for routing的test input。也是integration的一种。(11章会学习 request specs.)

RSpec-rails团队,推荐使用Capybara在系统测试中,不论是否使用JavaScript。


Setting Up Capybara  (API  doucument)

使用自己的API来和元素交互,使用驱动来管理实际的交互。默认不提供Js 交互,但可以配置使用一个无头的浏览器,如headless Chrome让JS交互被模仿。

gem "capybara-screenshot"用来闪存测试失败 (800星)放在support/system.rb

RSpec.configure do |config|
  config.before(:each, type: :system) do
    driven_by :rack_test
  end
end
require "capybara-screenshot/rspec" 

Using Feature Tests to Build a Feature

Writing a test

Given: 一个project ,2个task.

When/then: 用户填写form,你确认新的task建立

When/then:用户移动一个task up向上(增加向上和向下的按钮,task的排列?),你确认顺序改变。

system/add_tasks_spec.rb

⚠️ RSpec有rspec:feature生成器。

RSpec.describe "adding a new task" do

# given 3 data

  let!(:project) { create(:project, name: "Project Bluebook") }
  let!(:task_1) { create(
    :task, project: project, title: "Search Sky", size: 1) }
  let!(:task_2) { create(
    :task, project: project, title: "Use Telescope", size: 1) }
  it "can add and reorder a task" do

# when/then1:

    visit project_path(project)
    fill_in("Task", with:"Find UFOS")
    select("2", from: "Size")
    click_on("Add Task")
    expect(current_path).to eq(project_path(project))
    within("#task_3") do
      expect(page).to have_selector(".name", text: "Find UFOS")
      expect(page).to have_selector(".size", text: "2")
      expect(page).not_to have_selector("a", text: "Down")

# when/then2:

      click_on("Up")
    end
    expect(current_path).to eq(project_path(project))
    within('#task_2') do
      expect(page).to have_selector(".name", text: "Find UFOS")
    end
  end
end

 

The Capybara API: Navigating 

vist 对应 HTTP GET方法,

click_on(link/button)对应  HTTP POST方法

expect(page).to have_current_path(project_path(project))

⚠️最好

Rails 5 Test Prescriptions 第8章 Integration Testing with Capybara and Cucumber的更多相关文章

  1. Rails 5 Test Prescriptions 第3章Test-Driven Rails

    本章,你将扩大你的模型测试,测试整个Rails栈的逻辑(从请求到回复,使用端到端测试). 使用Capybara来帮助写end-to-end 测试. 好的测试风格,包括端到端测试,大量目标明确的单元测试 ...

  2. Rails 5 Test Prescriptions 第9章 Testing-JavaScript: Integration Testing,❌挂一个问题webpacker::helper

    使用Capybara进行JS的集成测试 谈论驱动 让测试通过 Webpack in Development Mode Js设计 是用户在网页上有好的体验的重要因素. 尽管如此,许多网页不测试JS. 部 ...

  3. Rails 5 Test Prescriptions 第4章 什么制造了伟大的测试

    伴随着程序成长,测试变长,复杂性增加,如何更高效的写测试,对以后开发不会造成麻烦. 测试本身没发被测试,所以一定要清楚,可控.不要加循环,不要过于复杂的自动编程. Cost and Value 成本和 ...

  4. Rails 5 Test Prescriptions 第11章其他部分的测试。

    Routes✅ Helper Methods✅ Controllers and Requests✅ Simulating Requests⚠️,看之前的博客 What to Expect in a R ...

  5. Rails 5 Test Prescriptions 第5章 Testing Models

    Rails,model层包含业务逻辑和储存逻辑.其中储存逻辑被ActiveRecord处理. 在model中,不是每件事都必须是ActiveRecord对象.model layer可以包含各种服务,对 ...

  6. Rails 5 Test Prescriptions 第10章 Testing for Security

    Web 安全是一个可怕的主题.所有的你的程序都依靠密码学,代码超出了你的控制. 尽管如此,你还是可以控制部分网页安全 --所有的logins和access checks和injection error ...

  7. Rails 5 Test Prescriptions 第10章 Unit_Testing JavaScript(新工具,learn曲线太陡峭,pass)

    对Js的单元测试是一个大的题目.作者认为Ruby的相关测试工具比Js的测试工具更灵活 大多数Js代码最终是关于响应用户的行为和改变DOM中的元素 没有什么javascript的知识点.前两节用了几个新 ...

  8. Rails 5 Test Prescriptions 第7章 double stub mock

    https://relishapp.com/rspec/rspec-mocks/v/3-7/docs/basics/test-doubles 你有一个问题,如果想为程序添加一个信用卡程序用于自己挣钱. ...

  9. Rails 5 Test Prescriptions 第6章Adding Data to Tests

    bcreate the data quickly and easily.考虑测试运行的速度. fixtures and factories.以及下章讨论的test doubles,还有原生的creat ...

随机推荐

  1. HDU 1403 Eight&POJ 1077(康拖,A* ,BFS,双广)

    Eight Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  2. Jmeter,常见参数 vars、prev、ctx 、props 类的api--beanshell

    http://www.cnblogs.com/fnng/p/5827577.html---------jmeter 性能测试 jmeter常见参数 vars.prev.ctx .props 类的api ...

  3. 设计模式之——Composite模式

    composite模式又叫做组合模式/复合模式. 它是一种能够使容器与内容具有一致性,创造出递归结构的模式. 示例程序是列出文件夹以及其内部文件与文件夹一览的功能: 可以由示例图看出,有一个电影文件夹 ...

  4. Linux下编译安装PHP扩展memcached

    [安装 libevent] $ tar zxvf libevent-2.0.20-stable.tar.gz $ cd libevent-2.0.20-stable/$ ./configure --p ...

  5. Spark2.0 shuffle service

    Spark 的shuffle 服务是spark的核心,本文介绍了非ExternalShuffleClient的方式,看BlockService的整个架构.ShuffleClient是整个框架的基础,有 ...

  6. gcc报错 can not be used when making a shared object; recompile with -fPIC

    使用google protobuf时,出现错误 /usr/bin/ld: /usr/local/lib/libprotobuf.a(message_lite.o): relocation R_X86_ ...

  7. Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, ...

    使用oracle数据库一个多月依赖这问题一直都得不到解决,最近任务不是很忙了,所以决定把这问题解决掉.写一篇文章做记录. 以上错误主要是net程序oracle数据库使用了Microsoft Enter ...

  8. Webwork 学习笔记

    1. 首先配置一个简单的webwork应用 核心jar: commons-logging.jarognl.jaroscore.jarvelocity-dep.jarwebwork-2.1.7.jarx ...

  9. mysql索引之主键索引

    MySQL目前主要有以下几种索引类型:1.普通索引2.唯一索引3.主键索引4.组合索引5.全文索引 二.语句 CREATE TABLE table_name[col_name data type] [ ...

  10. uva1391 2-SAT 问题

    题意在大白书上. 有3 种工作 abc 大于等于平均年龄的可以去做a c 工作, 小于平均年龄的可以去做 bc , 同样转化为2 -sat 去做, 因为对于每个人也只有2 种情况可以作为选择 #inc ...