Category:
TestNG
Using “alwaysRun” attribute of @Test annotation, we can make sure the test method will run even if the test methods or groups on which it depends fail or get skipped.
@Test
public void parentTest() {
Assert.fail(“Failed test”);
}
@Test(dependsOnMethods={“parentTest”}, alwaysRun=true)
public void dependentTest() {
System.out.println(“Running even if parent test failed”);
}
Here, even though the parentTest failed, the dependentTest will not get skipped instead it will executed because of “alwaysRun=true”. In case, we remove the “alwaysRun=true” attribute from @Test then the report will show one failure and one skipped test, without trying to run the dependentTest method.