When to choose a system test for Rails 5.1 test integration?

With the release of Rails 5.1, they included system tests. This means that we can test our JavaScript in Rails too. I see the Rails manual explaining the sample test creating an article in both directions: through a system test and through an integration test.

Now the question is: Before Rails 5.1, I wrote complex test cases in integration tests. But now I have two options for writing a test case. I can write a test case, for example

test: should create article 

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

So, when should I choose a system test for writing a test case and when should I choose integration tests?

+5
source share
1 answer

The short answer was given by MikDiet. For a long answer, check the documentation for system tests and integration.

System tests allow you to run tests in a real browser or headless driver to test interaction with your user.

A quick rule of thumb is that all tests that interact with Javascript must run as system tests. But you can also use them to test your flexible layout, as you can specify the browser screen size.

Integration tests are used to test the interaction of various parts of your application. They are commonly used to test important workflows in our application.

Integration testing is different from the fact that they do not run through the browser. They still allow you to interact with the HTML results page, but remember that this is the static output you're working with.

In integration tests, you mainly look at the behavior of controller actions, and not at what the user sees and interacts with. This piece of documentation can help you understand what integration tests are: Functional tests for your controllers .

+5
source

Source: https://habr.com/ru/post/1269091/


All Articles