When I test a method, can I trust other working methods?

If I use the unit testing method A and I use a number of other methods (or the getters property) in my test to check its behavior (in this case I do not use mocks), should I trust that these other methods work correctly and assume , what if they do not, will they be caught in tests by these methods?

+3
source share
3 answers

Yes, you should test only one method / block. For example, TestNG recommends that you make such assumptions, allowing you to define test dependencies. If you test a method foo()that depends on the method bar(), make your test dependent on the one that checks bar(). If the test bar()does not work, tests for foo()will not be performed.

The disadvantage of this assumption (when you cannot determine test dependencies) is that when the method is bar()violated, the tests for foo()and bar()fail, making it difficult to find the main cause of the problem.

+1
source

In short, yes.

, , - "" . ; , , ( ) . , , .

+2

, . unit test , unit test, .

0

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


All Articles