Thursday, December 23, 2010

Unit tests are not inherently good

Unit tests cause pain. Unit tests, by themselves, do not solve problems, do not make users happy, do not make maintainers happy, do not make a better product, and do not improve design. Unit tests make certain things hurt; nothing more and nothing less. But pain can indicate something is wrong and can lead you to do something else.

The first assumption behind unit tests (and bodily pain) is that if something hurts we'll pay attention and do something else instead. The second assumption is that what we do as an alternative will not only hurt less but make things better. For example, since unit tests make singletons and hard coded dependancies so painful, we can rely on dependency injection techniques and the single responsibility principal. This should cause code that is easier to test and understand and that responds to rapidly changing requirements.

So unit tests are one way to show what hurts and needs attention and avoid blundering into bad and potentially project-killing designs. The problem is when we can't or don't change how things are done. If we must rely on singletons, the filesystem, database, complex api calls, undefined behavior, or slow techniques then writing and running the unit tests will hurt. In these cases the costs of writing and maintaing unit tests can outweigh the benefits of running those tests.

13 comments:

  1. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
    apple watch service center chennai | apple iphone service center in chennai | apple iphone service center in chennai

    ReplyDelete
  2. Realme Mobile Service center in Chennai
    Realme Servicing by No. 1 Leaders Awesome Services On-time, Every time!
    Realme Mobile Service Center in Chennai

    ReplyDelete
  3. iPhone Service center in Bangalore No. 1 Leaders Awesome Services On-time, Every time!
    iPhone Service Center in Bangalore
    Apple Service center in Bangalore
    Apple Service Center in Bangalore

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Iphone service center in Chennai

    Iphone service Center in Chennai offers you best quality of Services On-time, Every time!
    IPhone Service Center in Chennai
    Apple Iphone Service center in Chennai
    Apple Service Center in Chennai
    Apple Service center in Chennai
    IPhone Service Center in Chennai

    ReplyDelete
  6. Honor service center in Chennai

    Honor Service Center in Chennai for the Best & Right Place to service your Honor mobile phone.
    Honor Service Center in Chennai

    ReplyDelete
  7. Nokia Mobile Service Center In Chennai
    Nokia Mobile Service Center In Chennai. Providing Fast, Honest, Reliable & Cost Effective Service Solutions to The Nokia Mobile Users.
    Nokia Mobile Service Center In Chennai

    ReplyDelete
  8. OPPO Service Center In Chennai
    OPPO Service Center Chennai is an end-to-end OPPO service and repair solutions Center.
    OPPO Service Center In Chennai

    ReplyDelete
  9. Ipad service center in Chennai

    Ipad service Center in Chennai offers you best quality of Services On-time, Every time!
    Ipad Service Center in Chennai

    ReplyDelete
  10. Lenovo Service Center in Chennai

    Lenovo Service Center Chennai
    Lenovo Service Center Chennai
    Lenovo service center near me in Chennai
    Lenovo service center near me in Chennai

    ReplyDelete
  11. WOW Great Post!!!

    Apple iPhone Service Center in Chennai

    Chennai No-1 Apple iPhone Service Center in Chennai
    Apple iPhone Service Center in Chennai
    Iphone Service Center in Chennai
    Iphone Service Center in Chennai
    Apple Service Center In Chennai
    Apple Service Center In Chennai

    ReplyDelete

  12. I like your suggestions they are really helpful. Thank you so much for sharing this post.
    OnePlus Repair Service center in Chennai

    ReplyDelete