| ▲ | seanwilson 2 days ago | |||||||
What's the problem of only keeping test 3 if it depends on test 2 and 1 passing anyway? The article mentions not to do this because "Deleting test1 loses us another property from the Test Desiderata—tests should be specific. That’s the property of tests where, when one fails, you know exactly where the problem is." but you'll know what line it failed on. And some test runners let you break a test into steps, where groups of lines are given a description. Or put each step + assert in a helper function (e.g. `doStep1AndAssert()`), and each test only calls these helper functions? Nothing is perfect, but copy/pasting chunks between tests like this isn't great when you want to refactor and it's repetitive to read. | ||||||||
| ▲ | troupo 2 days ago | parent [-] | |||||||
> What's the problem of only keeping test 3 if it depends on test 2 and 1 passing anyway? That depends. Sometimes test 1 tests a combination of ways (e.g., property testing, or just going through a bunch of various inputs), and only a few of those are needed for test 2. Sometimes you don't want your test 2 to be more complicated than it already is. Or the same things are needed checked in other tests. So you extract them into test 1. And sometimes (and in some of code bases most of the time) test 1 is redundant and unnecessary. That's why I always advocate investing in integration tests (test 20) and skip all the intermediate tests. | ||||||||
| ||||||||