I know there is a difference between assert and verify in Junit; the assert results in a runtime exception, causing test method execution to abort. To overcome this problem, we can have verify which will make test case fail, but allowing test execution to proceed rather than getting aborted.
I doubt there is any such built in approach in testNG. I do understand that best practices say, there should not be multiple asserts in same test case.
But, in practical world, we do come across scenarios where we need to have multiple checkpoints in one test case and we don't want our test method to abort because of one check point failure (test execution should proceed despite failure).
How can we use a soft assert mechanism, similar to verify, which will not abort test method when there is a checkpoint failure.
Example:
@Test(dataProvider = "getMailUrl")
public void testMail(email,subject);
Assert.assertFalse(subject.isEmpty);//1st checkpoint
Assert.assertNotNull(email); //2nd checkpoint
Assert.assertEquals(email, "[email protected]"); //3rd checkpoint
Now, I want test execution to proceed, even if the 1st checkpoint (validation of subject being not empty) fails. Definitely we will be not be using assert (hard assert). We will need concept of soft assert similar to verify (facilitated by Junit).
I understand, we have to build a customListener implementing TestNG interfaces or extending existing listeners such as TestListenerAdapter.
I am still struggling - how can we do this?