Ton*_*ony 3 java testing testng unit-testing
我正在使用注释expectedExceptionsMessageRegExp上的propery @Test来测试异常消息,但它没有正确执行.请参阅下面的代码.
单元测试代码:
@Test (dependsOnMethods = "test1", expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "incorrect argument")
public void testConverter()
{
try
{
currencyConverter = Converter.convert(val1,val2)
}
catch (MYException e)
{
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
申请代码:
if (val1 == null || val1.length() == 0)
{
throw new IllegalArgumentException("Val1 is incorrect");
}
Run Code Online (Sandbox Code Playgroud)
单元测试代码应检查异常消息,如果消息彼此不匹配,则测试应该失败.
目前这还没有发生.难道我做错了什么?
它似乎对我有用:
org.testng.TestException:异常被抛出错误的消息:期望"不正确的参数"但得到"val1不正确"
你能发一个显示问题的简单课程吗?(在这里或在testng-users邮件列表上)
| 归档时间: |
|
| 查看次数: |
4971 次 |
| 最近记录: |