Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to choose system test over integration test Rails 5.1?

Tags:

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 ?

like image 420
Zia Qamar Avatar asked Jun 22 '17 05:06

Zia Qamar


People also ask

Should I unit test or integration test?

While unit tests always take results from a single unit, such as a function call, integration tests may aggregate results from various parts and sources. In an integration test, there is no need to mock away parts of the application. You can replace external systems, but the application works in an integrated way.

Is a system test differ from an integration test?

System testing is a testing level in which tests are performed to know if a complete build aligns with functional and nonfunctional requirements made for it. In contrast, Integration testing is a testing stage where two or more software units are joined and tested simultaneously.

Which comes first integration testing or system testing?

In system testing, we check the system as a whole. In integration testing, we check the interfacing between the inter-connected components. It is performed after integration testing. It is performed after unit testing.

When should integration tests be run?

We normally do Integration testing after “Unit testing”. Once all the individual units are created and tested, we start combining those “Unit Tested” modules and start doing the integrated testing. The main function or goal of this testing is to test the interfaces between the units/modules.


1 Answers

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.

like image 195
jdno Avatar answered Sep 24 '22 01:09

jdno