Should tests containing unit test work in a specific order?

This is common to any language in which unit testing is performed.

Most unit test libraries provide a way to control the execution order of unit tests. Say I have a TestClass that defines twelve tests. Is there any good reason to try to control the execution order of twelve tests? Keep in mind that any startup / shutdown code has already taken care, because most libraries provide a way to do this. The advantage that I see in having an explicit testing order is that you can compose your tests so that each of them uses only the functions that it tested directly or has already been tested using the previous test. The disadvantage is the cost of maintenance to maintain the relevance of the order and to ensure that other developers understand why the order is what it is,and works on saving it.

Is it just not worth the effort?

+3
source share
2 answers

It is not worth the effort. More importantly, this is not a good practice. Each unit test should work independently of the others. If one of your tests depends on the first run, this is not a good test.

, , "" . , , ( A). B, , . - , A , B . . A , . , .

+5

, , , , , .

. , , , , , .

+1

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


All Articles