单元测试测什么


  • Thursday, Sep 22, 2016

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.

  • 开发过程中,单元测试应该来测试哪些可能会出错的地方和边界条件
  • 维护过程中,单元测试应该跟着bug report走,对于每一个bug都应该有个UT,用以保证相同的bug不会再出现
  • 不要被教条束缚
  • 对于一个方法,单元测试只应该关注输入和输出的对应情况

本文地址