Sunday, 15 August 2010

java - ExceptionHandling with TestNG -



java - ExceptionHandling with TestNG -

i referred below link - http://www.mkyong.com/unittest/testng-tutorial-2-expected-exception-test/ test exceptions using testng. how print message calling method? eg, when orderbo.save(null); called, how print - order empty!

you can use, along expectedexceptions parameter @test annotation, expectedexceptionsmessageregex. however, becomes quite messy annotation:

@test( expectedexceptions = myexception.class, expectedexceptionsmessageregex = "^regex message here$" ) public void testwhatever() { codethatraisessomeexception(); }

and note parameter value, parameter name suggests, regular expression...

rather that, why not this:

@test public void testwhatever() { seek { codethatraisessomeexception(); fail("no exception thrown!"); grab (myexception e) { assertequals(e.getmessage(), "the expected message here"); } }

ultimately, matter of tastes; yours finds latter more readable...

java

No comments:

Post a Comment