[英]Unit testing - how many test cases here
I have a method that takes an array as an argument, and returns true or false depending on the presence of a particular value. 我有一个方法,将数组作为参数,并根据特定值的存在返回true或false。
In this scenario how many test cases should be written? 在这种情况下,应该编写多少个测试用例?
I think 3: 我认为3:
I can think of 3 test cases: 我可以想到3个测试用例:
It is the code of the function you want to test, so you cannot tell how many test cases are useful. 它是您要测试的功能的代码,因此您无法确定有多少测试用例有用。 Think again what your code does, how will the value be found?
再想一想您的代码做什么,将如何找到该值?
An example: If your code tries to find a value with a certain name, and you make a string comparison, then think of the problems that can arise with string comparisons -> should the key be found case (in)sensitive, is null equal to an empty string, how does it handle duplicates and are other types converted correctly to strings (type juggling)? 示例:如果您的代码尝试查找具有特定名称的值,并且进行了字符串比较,那么请考虑一下字符串比较可能引起的问题->如果发现键区分大小写(不区分大小写),则为null等于转换为空字符串,它如何处理重复项,其他类型是否正确转换为字符串(类型变戏法)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.