Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    So... you're advocating to only write unit tests to help you learn/protect a system you're unfamiliar with, otherwise don't unit test?!! Maybe I've misunderstood your answer. If not, then this really isn't what unit testing is meant for. In particular, if you're a TDD advocate, you'll appreciate that writing a test first guides your efforts to implement minimal code, while Refactoring helps you to reinforce those efforts. Thus YAGNI ends up both a central tenet and a byproduct of your method of development. If your unit testing is getting complicated, IMHO you're probably doing it "wrong". Commented May 4, 2012 at 9:37
  • I'm saying unit testing provides a bridge over gaps in the understanding of an application. I did say that they were required to "extend" the application, in the sense that sometimes a feature and the impact of it is too difficult to keep track of all at once so unit tests can act as a framework to make that possible. Commented May 9, 2012 at 13:56
  • Yes, that is another use for Unit Testing, but certainly not the specific purpose of unit tests per-se. My comment however was to address the answer given, which I feel doesn't really address the OPs question satisfactorily. In particular, if you feel that unit tests are a distraction, or that they are only needed to help the least knowledgeable team member's understanding, then either you don't really understand how to apply unit tests effectively, or you perhaps feel tests are a last mile task. Either way, that is not the direction the OP was looking for his answers to come from. Commented May 15, 2012 at 6:28
  • For what it's worth, I do agree with you that where an application is very difficult to understand, unit tests can allow you to test ideas and use cases separately without needing to create a fully-fledged application. Personally I use unit test APIs to help me spike difficult problems. I will however always write unit tests for my code, even where it may seem fairly trivial, and I do this test first in order to get the real benefit of tests, which is confidence to change code over time without fearing the code will break and require extensive independent testing later. Commented May 15, 2012 at 6:33
  • In expressing my answer I was attempting to come up with a concise and all encompassing rule of thumb which answers whether unit testing is appropriate to what you are doing or not. In that respect therefore responding directly to the OPs question. I said also to write tests if the complexity "will likely in the future exceed" understanding to cover the case you suggested of "it may seem fairly trivial [now, but later...]". Commented May 15, 2012 at 11:38