基本的jUnit问题(Basic jUnit Questions)
我正在用一个
multiply()
方法测试一个String乘数类,该方法以2个数字作为输入(如String
)并返回结果数字(如String
)public String multiply(String num1, String num2);
我已经完成了实现并创建了一个测试类,其中包含以下与输入String参数as相关的测试用例
- 有效的数字
- 人物
- 特殊符号
- 空字符串
- 空值
- 0
- 负数
- 浮动
- 边界值
- 有效但其产品超出范围的数字
- 数字会加号(+23)
现在我的问题是这些:
我想知道“每一个”assertEquals()是否应该在它自己的测试方法中? 或者,我可以将类似的测试用例(如testInvalidArguments())分组以包含涉及无效字符的所有断言,因为它们都引发相同的NumberFormatException?
如果测试像字符(“a”)这样的输入值,是否需要为所有场景包含测试用例? “a”作为第一个参数“a”作为第二个参数“a”和“b”作为2个参数
根据我的理解,这些单元测试的好处是要找出用户输入可能失败并导致异常的情况。 然后,我们可以给用户一个有意义的消息(要求他们提供有效的输入)而不是例外。 这是正确的吗? 而且,这是唯一的好处吗?
上面提到的11个测试用例是否足够? 我错过了什么? 我过度了吗? 什么时候够了?
从上述观点来看,我是否成功地测试了multiply()方法?
I was testing a String multiplier class with a
multiply()
method that takes 2 numbers as inputs (asString
) and returns the result number (asString
)public String multiply(String num1, String num2);
I have done the implementation and created a test class with the following test cases involving the input String parameter as
- valid numbers
- characters
- special symbol
- empty string
- Null value
- 0
- Negative number
- float
- Boundary values
- Numbers that are valid but their product is out of range
- numbers will + sign (+23)
Now my questions are these:
I'd like to know if "each and every" assertEquals() should be in it's own test method? Or, can I group similar test cases like testInvalidArguments() to contains all asserts involving invalid characters since ALL of them throw the same NumberFormatException ?
If testing an input value like character ("a"), do I need to include test cases for ALL scenarios? "a" as the first argument "a" as the second argument "a" and "b" as the 2 arguments
As per my understanding, the benefit of these unit tests is to find out the cases where the input from a user might fail and result in an exception. And, then we can give the user with a meaningful message (asking them to provide valid input) instead of an exception. Is that the correct? And, is it the only benefit?
Are the 11 test cases mentioned above sufficient? Did I miss something? Did I overdo? When is enough?
Following from the above point, have I successfully tested the multiply() method?
原文:https://stackoverflow.com/questions/2710545
最满意答案
我在预览门户网站(portal.azure.com)也有,但它在旧门户(manage.windowsazure.com)
I have it too in preview portal (portal.azure.com), but it works in the old portal (manage.windowsazure.com)
相关问答
更多-
我在预览门户网站(portal.azure.com)也有,但它在旧门户(manage.windowsazure.com) I have it too in preview portal (portal.azure.com), but it works in the old portal (manage.windowsazure.com)
-
我记得默认情况下JMeter在某些情况下作为服务器运行时绑定到localhost,因此您需要通过SSH隧道连接您的从jmeter-server或在jmeter-server上使用参数-Djava.rmi.server.hostname=10.6.149.95命令行,以便绑定到LAN IP。 干杯, My problem is solved. My server default java version is 1.5. I upgrade java version. jmeter doesn't suppor ...
-
你确认你在这里也改了它: Webmin - >网络 - >网络配置 - >主机名和DNS客户端,您可以在那里更改主机名。 还检查 Virtualmin - >系统设置 - >服务器模板 - >绑定DNS域 Have you confirmed that you have also changed it here: Webmin -> Networking -> Network Configuration -> Hostname and DNS Client, and you can change your ...
-
在主机名第一次更改后,rabbitmq-server无法启动(rabbitmq-server fails to start after hostname has changed for first time)[2022-08-18]
删除旧的RabbitMQ安装来解决这个问题。 以下是重新安装RabbitMQ的步骤。 这些命令以root用户身份运行: 停止RabbitMQ: rabbitmqctl stop 更改/etc/hosts 更改/etc/hostname 卸载旧的RabbitMQ: dpkg -P rabbitmq-server 删除RabbitMQ的数据库: rm -rf /var/lib/rabbitmq 找到erlang的进程,运行兔子: ps ax | grep rabbit ps ax | grep rabbit 杀 ... -
您将能够获得另一个SSL证书,但您只能在当时安装单一证书。 只能在频繁限定的域名( FQDN )上发布SSL。 因此,要么删除现有的证书,必须安装新的证书,但不能同时使用两者。 只有单一SSL证书可以在服务器上绑定,因此它会自动替换现有的证书 。 You would be able to get another SSL certificate, but you will only able to install single certificate at the time. SSL can be only ...
-
更改主机名: hostname ***或vi /etc/hosts 重启docker: sudo systemctl restart docker 你可以看到'名字'用户docker info change hostname: hostname *** or vi /etc/hosts restart docker: sudo systemctl restart docker You can see 'Name' user docker info
-
有两个“标准”Azure拥有的域 - v1移动服务使用xxx.azure-mobile.net - v2移动应用程序使用xxx.azurewebsites.net。 此外,您还可以使用自定义域功能引入您拥有的任何域。 请参阅https://azure.microsoft.com/en-us/documentation/articles/web-sites-custom-domain-name/ 您不能携带azure-mobile.net域名,因为您不拥有它。 获得具有azure-mobile.net域名的v ...
-
PHP主机名绑定(PHP hostname bindings)[2024-01-05]
认真考虑使用Swift Mailer的“NativeMail”甚至是“Sendmail”界面。 这两个选项都可以避免网络流量,内部IP地址和收到的标头。 它们也会明显更快,这对您来说可能很重要。 如果您坚持使用SMTP,请注意Swift使用$_SERVER["SERVER_ADDR"]变量“自动检测”本地主机名(在SMTP对话框中提供),该变量不会由CLI设置。 如果你不能安排这个有更好的值,你可以将它作为第二个参数传递给Swift构造函数,如: $swift = new Swift(new Swift_C ... -
将代码更改为 HttpListener listener = (HttpListener)app.Properties["System.Net.HttpListener"]; listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm; 在自主Host Web API中,它解决了这个问题。 Change the code to HttpListener listener = (HttpListener)app.Properties["System ...
-
好吧,我想出来了 - 结果证明DNS WAS设置不正确! 当我开始创建一堆虚拟站点并使用本地计算机的主机文件进行播放时,我能够缩小问题的范围,并发现所有内容似乎都路由正常。 所以,显然IIS正如预期的那样工作。 所以,我接着一再打电话给GoDaddy,直到找到一个同意帮助我使用Google域名的人。 显然,根据我的理解,我将IP地址设置在错误的位置,只将域名转发为IP地址,因此没有主机名可供IIS匹配,这就是为什么它拉出默认网站(没有绑定)没有问题,只有默认网站! 他将我引导到另一个屏幕(DNS区域文件选项 ...