Tests… That’s a story ! Here is my opinion at the time I am writing this article.
Who ?
EVERYBODY. There should not be any “test” job title, it’s a team responsibility including the product owner !
Manual VS Automated -> 🤖
Forget about manual stuff. You won’t have the courage, time, patience… to run it frequently enough. So go for automated tests.
Types of Automated tests
What kind of tests should you write ? If you look at the “pyramid of tests” sounds like you have the choice.
I recommend writing mostly unit tests. Mainly because they give you a good confidence of "can I push to prod"
while being quite easy to write, maintin, and run !
Unit tests
Run time
You should be able to run the whole test suite in a few minutes. Otherwise, how can you develop without a test feedback loop ?
It means you should not target 100% coverage: be smart in what you test… you want a good confidence of "can I push to prod"
not perfection.
Test data
- unit tests are independant from each other, so recreate the whole data you need for each test.
- mock external providers data, don’t rely on other systems
failures
Most of the time not a bug, so check:
- the code -> check if you need to adapt your test
- the environment -> try to stabilize your environment
- the test assumptions
TDD
Begin your feature with the test in mind, or even better with the unit test. Never write tests after the push to prod, this is a big warning for your product. Take time to refactor your tests as the code evolves.
Flaky tests
test that sometimes pass, sometimes fails are the worst: you loose the good confidence of "can I push to prod"
so remove them from your CI.
Service tests & UI tests
IMO, they are slow, flaky, and hard to maintain. But, they have value complementing unit tests. So, you might use just a few of them to cover the most critical paths of your application.
Integration test & performance test
IMO, should be manual. Under the hood, decoupling your app from external providers is mandatory.
Resources
- 🎥 1h video from @badrij @jezhumble
- Uncle bob’sblog