何时选择系统测试而不是集成测试Rails 5.1? [英] When to choose system test over integration test Rails 5.1?

查看:36
本文介绍了何时选择系统测试而不是集成测试Rails 5.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着Rails 5.1的发布,它们包括系统测试。这意味着我们也可以在Rails中测试我们的JavaScript。
我看到Rails指南以两种方式解释了示例测试创建文章:通过系统测试和通过集成测试。



现在,问题是:在Rails 5.1之前,我正在集成测试中编写复杂的测试用例。但是现在我有两个选择来编写测试用例。
我可以编写类似

  test的测试用例:应该创建文章

在集成测试中,但我也可以在系统测试中编写相同的测试用例。



所以我什么时候应该选择系统测试来编写测试用例以及何时选择集成测试?

解决方案

简短的答案由MikDiet给出。对于长答案,请查看有关系统和集成测试的文档


系统测试允许在真实的浏览器或无头驱动程序中运行测试,以测试用户与应用程序的完整交互。



集成测试用于测试应用程序各个部分之间的交互方式。它们通常用于测试应用程序中重要的工作流程。


集成测试是不同的,因为它们不是通过浏览器运行的。它们仍然允许您与结果页面的HTML进行交互,但是请记住,它是您使用的静态输出。



在集成测试中,您主要关注的是控制器动作的行为,而不是用户看到并与之交互的内容。文档的此部分可能有助于您了解有关集成测试的全部内容:控制器的功能测试


With the release of Rails 5.1, they included system tests. Which means we can test our JavaScript too in Rails. I see Rails guide explains a sample test creating article in both ways: via system test and via integration test.

Now the question is: before Rails 5.1 I was writing complex test cases in integration tests. But now I have two options to write a test case. I can write test case like

test: should create article

in integration test, but I can also write the same test case in system test.

So when should I choose system test to write a test case and when to choose integration tests ?

解决方案

The short answer has been given by MikDiet. For the long answer, check out the documentation on system and integration tests.

System tests allow for running tests in either a real browser or a headless driver for testing full user interactions with your application.

A quick rule of thumb is that all tests interacting with Javascript need to be run as system tests. But you could also use them to test your responsive layout, since you can specify the screen size of the browser.

Integration tests are used to test how various parts of your application interact. They are generally used to test important workflows within our application.

Integrations tests are different because they are not run through the browser. They still allow you to interact with the HTML of the result page, but remember that it's static output you work with.

In integration tests, you are mostly looking at the behavior of the controller actions and not so much on what the user sees and interacts with. This part of the documentation might help you understand what integration tests are all about: Functional Tests for Your Controllers.

这篇关于何时选择系统测试而不是集成测试Rails 5.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆