Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Eh, I disagree. I find the traditional test pyramid a suitable model still.

Sure, unit tests require much more maintenance than higher level tests, but they give you confidence that the smallest parts of the codebase work as intended. They're the ones that test all sorts of failure scenarios and edge cases, which is typically not the purpose of integration tests. They also should be inexpensive to run, simple to write, and require minimal setup.

Unit tests should also give you immediate feedback that something went wrong, by pinpointing the exact component that failed. In contrast, integration tests might happily pass, as they're not granular enough to cover all code paths. Integration tests focus on, well, that the integration between components is working as expected.

So I still insist on having mostly unit tests, many integration tests, and some E2E tests. Doing it otherwise because it saves you maintenance efforts will haunt you in the long run.



Most people don't have a rather obvious interface on their units to tests. If you are implementing one of the CS3025 (your university probably used a different number scheme) algorithms, then the interface is obvious and worth a unit tests. Even if there is some doubt (rare), you will have so many users that is isn't possible to change anymore anyway.

Most of us are writing glue code that isn't as clear what the api should be. Unit tests just get in the way of refactoring when requirements change.


On the one hand, I agree that writing unit tests before the design has settled and the interfaces are stable can be frustrating. Many people find TDD a chore because of this.

But if you delay adding unit tests until after the interfaces are more or less stable, it gives you higher confidence to refactor the implementation, which is invaluable.

On the other hand, the benefit of TDD is that it helps with the actual API design. You immediately experience the API as a user, and this process drives the implementation, and ensures you end up with a friendly and testable API. If you add tests after the design, then you might have a more difficult time refactoring the implementation to make it testable, and the DX could suffer.

So I see both sides of the argument, but in either case, unit tests are very important, and I wouldn't avoid them just because they're a chore to maintain.


TDD gives you a testable interface, but otherwise doesn't help think what the api should be.

You can so TDD using only integration tests. This means tests are not added after the design. It only means that your individual functions don't have tests. I do this allowed the time, it makes refactoring easier.

The most common objection: how do you know what failed? Turns out to be a non issues, since I make my tests fast I can run them often and thus the failure has an obvious cause: the last thing I changed.


Unit tests help in a very specific circumstance - when you're testing complex calculations or logical code with simple inputs or outputs.

Some projects have almost zero code like this.

In all other situations they suck. When they fail it doesnt necessarily mean anything is wrong and vice versa. It just mirrors a portion of the code. It's a lot of expensive maintenance with no payoff.

In contrast integration tests are usually much more meaningful - they will typically test a real system or user interaction.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: