How do you tell that your unit tests are correct?

后端 未结 16 1394
广开言路
广开言路 2020-12-28 16:23

I\'ve only done minor unit testing at various points in my career. Whenever I start diving into it again, it always troubles me how to prove that my tests are correct. How

16条回答
  •  误落风尘
    2020-12-28 17:02

    This is one of the advantages of TDD: the code acts as a test for the tests.

    It is possible that you'll make equivalent errors, but it is uncommon in my experience.

    But I have certainly had the case where I write a test that should fail only to have it pass, which told me my test was wrong.

    When I was first learning unit testing, and before I was doing TDD, I would also deliberately break the code after writing the test to ensure that it failed as I expected. When I didn't I knew the test was broken.

    I really like Bob Martin's description of this as being equivalent to double entry bookkeeping.

提交回复
热议问题