Reputation: 1423
Is any way where I can mark test fail in TestNG report and continue same test.. Problem with me that Test would not execute when test Case fail by using Assert.assertEquals(acutalResult,ExpectedResult). I have tried with try catch block but problem is still exist.
Upvotes: 1
Views: 4587
Reputation: 327
You may want to read up on "Soft Assertion vs Hard Assertion". Just google it. There is plenty information on how to do that.
A "soft assertion" allows you to to assert a (partial) test result without breaking the testing flow. You basically log your result (see example below) what ever it may look like and veryify it later after the test has finished by either raising a failure manually or assert the "log" (Check if failures avalable: If not - pass, if with failures - set fail)
Have a look at this resource: Exampl
Upvotes: 0
Reputation: 21149
TestNG will create a xml file, 'testng-failed.xml' after your test failure; It contains all the failed test Methods. It can be used to re-run your Failed tests manually or automatically.
Upvotes: 0
Reputation: 1525
Add try/catch for each assert seperately. Define a variable and increment if there is any failure. And finally fail the test case if it is more than 0.
try{
//assertion cod
}catch(AssertionError ae){
Reporter.log(Print failure to report);
errorCounter++;
}
if(errorCounter > 0){
fail(message);
}
Upvotes: 0
Reputation: 8531
An assert failure throws an AssertionError. Its an Error and not an Exception. You might have tried to capture an Exception in your catch and hence, it would not have worked. What you need is soft assertions. Try searching for soft assertions and you can get other implementation approaches as well.
Upvotes: 0