3 ms·
> Instead the pyramid says we should write a lot of unit tests. This leads to an inside out approach testing the structure of the system rather its behaviour.
by cenny 5y ago
> Instead the pyramid says we should write a lot of unit tests. This leads to an inside out approach testing the structure of the system rather its behaviour.
No it does not. Unit tests should test behavior.
> Only use mocks for truly external systems (e.g. mail service). The database should be part of the tests. Do not stub it.
First, mocks and stubs are not the same thing.
Secondly, stub fragile dependencies in unit tests is a good rule of thumb if you want easy, fast and non-erratic tests.
> Never change your code without having a red test. This is pretty common practice in TDD.
No, In TDD we change our code all the time without a red test, we call it refactoring and we only do that when the test is green.
There are so many misunderstandings in testing and TDD. I wished more people would read Kent Becks book [Test-Driven Development: by example](https://www.programmingbooks.dev/#test-driven-development https://www.programmingbooks.dev/#test-driven-development) and then the amazing book by Gerard Meszaros [XUnit Test Patterns](https://www.programmingbooks.dev/#xunit-test-patterns https://www.programmingbooks.dev/#xunit-test-patterns).
In the end I'm just happy if more people practice TDD and understand it's a skill to learn like everything else and not a silver bullet.
- WolfOliver 5y ago> Unit tests should test behavior. Yes, they should but often they do not. The likelihood to get it right is higher using an outside-in approach.