<story><title>Write tests. Not too many. Mostly integration (2017)</title><url>https://blog.kentcdodds.com/write-tests-not-too-many-mostly-integration-5e8c7fff591c</url></story><parent_chain><item><author>hathawsh</author><text>My rule of thumb: tests cast away fear. Whenever I get that sinking feeling that I&amp;#x27;ll break things when I change the code, I write tests until my doubts disappear. It works every time.&lt;p&gt;In response to the article: it&amp;#x27;s true that &amp;quot;you should very rarely have to change tests when you refactor code&amp;quot;, however, most of the time, most coders are changing the expected behavior of the code due to changed or added requirements, which is not refactoring. Tests should change when the requirements change, of course. I am not contradicting the article, only clarifying that the quoted statement does not apply outside refactoring. (Refactoring is improving the design or performance of code without changing its required behavior.)</text></item></parent_chain><comment><author>efdee</author><text>In my experience, a lot of unit tests are written with mocks, expectations, and way too much knowledge of the implementation details, which leads to broken tests simply by refactoring, even if the behavior does not change at all.&lt;p&gt;If you test units in isolation, while adhering to SRP which results in many smaller units depending on eachother to do a task, then simply refactoring without changing behavior screws up a considerable portion of your tests.&lt;p&gt;As for &amp;quot;tests cast away fear&amp;quot;, that is definitely true. Whether or not the lack of fear is warranted is something else, and depends heavily on the quality of the unit tests. I&amp;#x27;ve seen plenty of devs confident of their change because it didn&amp;#x27;t break any unit tests, only to discover that it broke something they forgot to test.</text></comment>
<story><title>Write tests. Not too many. Mostly integration (2017)</title><url>https://blog.kentcdodds.com/write-tests-not-too-many-mostly-integration-5e8c7fff591c</url></story><parent_chain><item><author>hathawsh</author><text>My rule of thumb: tests cast away fear. Whenever I get that sinking feeling that I&amp;#x27;ll break things when I change the code, I write tests until my doubts disappear. It works every time.&lt;p&gt;In response to the article: it&amp;#x27;s true that &amp;quot;you should very rarely have to change tests when you refactor code&amp;quot;, however, most of the time, most coders are changing the expected behavior of the code due to changed or added requirements, which is not refactoring. Tests should change when the requirements change, of course. I am not contradicting the article, only clarifying that the quoted statement does not apply outside refactoring. (Refactoring is improving the design or performance of code without changing its required behavior.)</text></item></parent_chain><comment><author>bigiain</author><text>I find it helps when I consider the tests to be part of the code. If I need to change existing functionality, of course I&amp;#x27;ll need to change the tests so they test the new requirement(s). If I&amp;#x27;m adding new functionality I add new tests to test the new requirement, but I shouldn&amp;#x27;t break any of the old tests when I do that. If I&amp;#x27;m changing code with no requirements changes (as in, pure refactoring, not &amp;quot;tidying up as part of new feature development&amp;quot;), all the existing tests need to pass unchanged...</text></comment>