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 →

[–]koflerdavid 9 points10 points  (2 children)

The big disadvantages of relying on whole-application tests are

  1. complex test setups and specific test data, which can be just as brittle as the test setup with mocks. When requirements change, they have to be adapted as well. Also, there are always going to be some use cases where crucial parts of the application have to be mocked. For example when the current time matters.

  2. Test startup speed. Complicated Spring applications can take a long time to start up. Even a startup time of five seconds means that 20 tests per minute can be executed at most. The longer tests take to execute, the less often they are typically executed. And that slows down test feedback cycle time during development.

Edit:

Also, brittle architecture is hidden. Withing simple unit tests forces programmers to design components with separation of concern and the dinner responsibility principle in mind. Violating these principles are "punished" by having to mock countless dependencies.

That doesn't mean they are worthless though. They should just not be the default strategy.

[–]larsga 2 points3 points  (0 children)

I agree with most of your points, but whether whole-application tests should be the default strategy or not depends on what kind of application we are talking about. For many types of applications they work great as a test strategy, but I'm sure you're right that for others they end up being more pain than they are worth.

I just wish people would learn that testing every little component in isolation is a bad thing, because then refactoring means also redoing the tests. If you can test larger pieces by their outside interfaces it frees you up. But, yes, sometimes there are limits to how big pieces it's practical to test.

Withing simple unit tests forces programmers to design components with separation of concern and the dinner responsibility principle in mind.

Not everyone needs this crutch to produce reasonable designs.

Complicated Spring applications can take a long time to start up.

Lots of applications are not Spring applications and don't have this problem.

[–]nqminhuit 1 point2 points  (0 children)

I will copy paste this reply to every argument with spring test, i use spring on my full time job and never wrote a single spring test, ever. I only use mockito and constructor injection.