Найти в Дзене

Пирамида тестирования была ошибкой


Тестирование собственного кода, неотъемлемая часть разработки у профессиональных разработчиков. Но тестирование тестированию рознь. Обычно, когда речь заходит о тестировании, то в разговоре сразу всплывает пирамида тестирования по Фаулеру и заходит речь о юнит тестах, о том что их должно быть много, в первую очередь надо писать их и так далее.

Когда-то очень много лет назад, я пошел по этому же пути, но быстро понял что фокус на юнит тестах не самое эффективное вложение. Сейчас об этом уже говорят многие и пишут тоже https://kentcdodds.com/blog/the-testing-trophy-and-testing-classifications Если вы не знакомы с Кентом, то обязательно посмотрите, он говорит о сдвиге парадигмы (хотя откровенно говоря, для меня подобная структура всегда была более естественной). Но есть и другой Кент, на которого очень любят ссылаться все кто пишут тесты. А вот что он сказал в 2005 году:

I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don’t typically make a kind of mistake (like setting the wrong variables in a constructor), I don’t test for it. I do tend to make sense of test errors, so I’m extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong.
Different people will have different testing strategies based on this philosophy, but that seems reasonable to me given the immature state of understanding of how tests can best fit into the inner loop of coding. Ten or twenty years from now we’ll likely have a more universal theory of which tests to write, which tests not to write, and how to tell the difference. In the meantime, experimentation seems in order.

И я с ним согласен
1 минута