▲ | imiric 6 days ago | |
> You mean just like unit tests where every useful interaction between units is mocked out of existence? Sure, that is a risk. But not all unit tests require mocking or stubbing. There may be plenty of pure functions that are worth testing. Writing good tests requires care and effort, like any other code, regardless of the test type. > And that's the main issue: people pretend that only unit tests matter, and as a result all other forms of testing are an afterthought. Huh? Who is saying this? The argument is coming from the other side with the claim that unit tests don't matter. Everyone arguing against this is saying that, no, all tests matter. (Let's not devolve into politics... :)) The idea of the test pyramid has nothing to do with one type of test being more important than another. It's simply a matter of practicality and utility. Higher-level tests can cover much more code than lower-level ones. In projects that keep track of code coverage, it's not unheard of for a few E2E and integration tests to cover a large percentage of the code base, e.g. >50% of lines or statements. This doesn't mean that these tests are more valuable. It simply means that they have a larger reach by their nature. These tests also require more boilerplate to setup, external system dependencies, they take more time to run, and so on. It is often impractical to rely on them during development, since they slow down the write-test loop. Instead, running the full unit test suite and a select couple of integration and E2E tests can serve as a quick sanity check, while the entire test suite runs in CI. Conversely, achieving >50% of line or statement coverage with unit tests alone also doesn't mean that the software works as it should when it interacts with other systems, or the end user. So, again, all test types are important and useful in their own way, and help ensure that the software doesn't regress. | ||
▲ | troupo 6 days ago | parent [-] | |
> Sure, that is a risk. But not all unit tests require mocking or stubbing. Not all integrations require mocking or stubbing either. Yet somehow your argument against integration tests is that they somehow won't trigger failure scenarios. > The argument is coming from the other side with the claim that unit tests don't matter. My argument is that the absolute vast majority of unit tests are redundant and not required. > The idea of the test pyramid has nothing to do with one type of test being more important than another. It's simply a matter of practicality and utility. You're sort of implying that all tests are of equal importance, but that is not the case. Unit tests are the worst of all tests, and provide very little value in comparison to most other tests, and especially in comparison to how many unit tests you have to write. > it's not unheard of for a few E2E and integration tests to cover a large percentage of the code base, e.g. >50% of lines or statements. This doesn't mean that these tests are more valuable. So, a single E2E tests a scenario that covers >50% of code. This is somehow "not valuable" despite the fact that you'd often need up to a magnitude more unit tests covering the same code paths for that same scenario (and without any guarantees that the units tested actually work correctly with each other). What you've shown, instead, is that E2E tests are significantly more valuable than unit tests. However, true, E2E tests are often difficult to set up and run. That's why there's a middle ground: integration tests. You mock/stub out any external calls (file systems, API calls, databases), but you test your entire system using only exposed APIs/interfaces/capabilities. > These tests also require more boilerplate to setup, external system dependencies, they take more time to run, and so on. And the only reason for that is this: "people pretend that only unit tests matter, and as a result all other forms of testing are an afterthought." It shouldn't be difficult to test your system/app using it the way your users will use, but it always is. It shouldn't be able to mock/stub external access, but it always is. That's why instead of writing a single integration test that tests a scenario across multiple units at once (at the same time testing that all units actually work with each other), you end up writing dozens of useless unit tests that test every single unit in isolation, and you often don't even know if they are glued together correctly until you get a weird error at 3 AM. |