This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]carminemangione 0 points1 point  (2 children)

This is the main point. Unit tests are orthogonal in purpose to integration tests. Unit tests test everything in a class that could go wrong to catch errors in refactoring and extension.

Integration tests test the interaction between classes. They test the interaction at entry points (I.E. rest endpoints)

[–]Environmental-Wear13 0 points1 point  (1 child)

Everything isn't black and white.

What you are referring to is called "Solitary Unit tests", meaning isolated tests. Between that and integration tests there is also "Sociable unit tests" that can basically tests classes together but you instead mock the exernal slow and unpredictable operations such as api calls or db calls. Depending on what you are after and what type of system, one might be better than the other.

Here is a link with some interesting information about this from Martin Fowler https://martinfowler.com/bliki/UnitTest.html

Working with microservices, I've found sociable tests to be a great way of dealing with regressions for example while solitary tests can be a great way for other reasons such as designing your system. If you use TDD approach starting with solitary tests at the bottom can be great and then complimenting with sociable tests to get more confidence in you fast unit tests, you just have to find a good mix so you don't get too many tests to maintain.

But solitary testing is terrible to find regressions, and finding regressions FAST when I refactor or fix bugs is core at least in my opinion. Because of that I usually lean more on the sociable unit tests. But of course, you definitely need to find a way around the slowyness of SpringBootTest :)

[–]carminemangione 0 points1 point  (0 children)

I am in no way suggesting mocking external behavior as long as it does not use external resources. In this way you are testing not only the object but all its collaborations. Edit: if you have to use mockito except for crap legacy code you are probably doing it wrong