Search code examples
testngtestng-dataprovider

TestNG dependent method should not get skipped even if one method of dataprovider fails


Let's say we have 2 methods with dataprovider in TestNG.

@Test(dataProvider = dpA)
testA(String str){
    logger.info(str);
}

@Test(dataProvider = dpB, dependsOnMethods = {"testA"})
testB(String str){
    logger.info(str);
}

@DataProvider(name = "dpA")
public Object[][] dpA(){
    return new Object[][] { { "This test fails"}, {"This test passes"} };
}

@DataProvider(name = "dpB")
public Object[][] dpB(){
    return new Object[][] { { "new test"}, {"some test"} };
}

Given: The testB should execute only after testA that's why we have used dependsOnMethods.
Current scenerio: TestNG skips testB even if any case from dataprovider fails.
Target: testB should run if any one case from dataprovider passes.


Solution

  • Currently dependsOnMethods is a hard dependency i.e., it has to be completely satisfied before a dependent method can be executed.

    A @DataProvider powered @Test method is basically just one way to run the same @Test multiple times (of-course with multiple sets of data instead of using the same data which is what happens when you set the invocationCount attribute of @Test method).

    So this cannot be achieved in current TestNG as it stands, without mucking around with the test results etc., and causing un-explained behaviours.

    If this is something that you would like to see in TestNG then I would suggest that you please file this as a defect within the TestNG issue page and start off a discussion over this in https://github.com/cbeust/testng/issues