我应该为每个函数/方法编写多少个单元测试? [英] How many unit tests should I write per function/method?
本文介绍了我应该为每个函数/方法编写多少个单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您是为每个函数/方法编写一个测试,在测试中进行多项检查,还是对每个检查进行一次测试?
Do you write one test per function/method, with multiple checks in the test, or a test for each check?
推荐答案
每个检查一个测试和每个实例的超级描述性名称:
One test per check and super descriptive names, per instance:
@Test
public void userCannotVoteDownWhenScoreIsLessThanOneHundred() {
...
}
当测试失败时,只有一个断言和使用好名字都可以给我一个更好的报告.他们对我尖叫:你违反了那个规则!".
Both only one assertion and using good names gives me a better report when a test fails. They scream to me: "You broke THAT rule!".
这篇关于我应该为每个函数/方法编写多少个单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文