How do I test expectedExceptionsMessageRegExp (exception message) using TestNG?
Posted
by Thomman
on Stack Overflow
See other posts from Stack Overflow
or by Thomman
Published on 2010-04-14T15:25:39Z
Indexed on
2010/04/14
17:33 UTC
Read the original article
Hit count: 253
I'm using expectedExceptionsMessageRegExp annotation to test exception message, but the this is not executing correctly.please see the below code.
Unit Test code:
@Test (dependsOnMethods = "test1", expectedExceptions = IllegalArgumentException.class ,
expectedExceptionsMessageRegExp = "incorrect argument")
public void testConverter()
{
try
{
currencyConverter = Converter.convert(val1,val2)
}
catch (MYException e)
{
e.printStackTrace();
}
}
Application code:
if (val1 == null || val1.length() == 0)
{
throw new IllegalArgumentException("Val1 is incorrect");
}
The unit test code should check the exception message , if both message are not matching , it should throw fail (unit test failed) .
At present this is not happening , Am i doing something wrong?
© Stack Overflow or respective owner