I know I should write tests, but I never know where to start or when to stop. Should I test everything, aim for 100 percent coverage, or only critical parts?
#testing#best-practices#quality
DEV3 Developer Forum
Every post is reviewed first. Usually reviewed within 24 hours.
I know I should write tests, but I never know where to start or when to stop. Should I test everything, aim for 100 percent coverage, or only critical parts?
#testing#best-practices#quality
Short answer: test the behaviour that would hurt most if it broke, and the code that is easy to get wrong. Coverage is a signal, not a goal.
A reasonable mix has many unit tests, a moderate number of integration tests and a few end-to-end tests.
it("rejects a discount code after its expiry date")
High coverage with weak assertions is false comfort. Use coverage to find untested areas, and review it for critical modules, but do not chase 100 percent for its own sake.
Start with the riskiest feature and add tests as you touch code.