-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dataprovider is executed for ignored tests in case of the BeforeClass failure #2049
Comments
Quick question : why do you want the data provider to be executed when a |
Hi! |
That's why I wrote:
|
Ah ok! Sorry I misread it. Let me see what is going on. I agree. It's a bit counter intuitive for the data provider to still run when there is a config failure at class level. |
@baflQA - Fixing this issue is going to be tricky from TestNG side. It looks like fixing this would cause a lot of regression. So here's an easy work-around that would ensure that the data provider doesn't get executed if there's a configuration failure. import static org.testng.Assert.fail;
import com.rationaleemotions.github.issue2049.SampleTestClass.FailureDetecter;
import org.testng.IConfigurationListener;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners(FailureDetecter.class)
public class SampleTestClass {
@BeforeClass
public void beforeClass() {
System.err.println("BEFORE CLASS");
fail();
}
@Test(dataProvider = "dp1master")
public void test1(Class<?> clazz) {
System.err.println("Running test for class " + clazz.getSimpleName());
}
@DataProvider
public Object[][] dp1master(ITestContext ctx) {
if (ctx.getAttribute(FailureDetecter.FAILURE) != null) {
throw new RuntimeException("Failure");
}
return new Object[][] {new Object[] {Object.class}, {Object.class}};
}
public static class FailureDetecter implements IConfigurationListener {
public static final String FAILURE = "failure";
@Override
public void onConfigurationFailure(ITestResult itr) {
itr.getTestContext().setAttribute(FAILURE, Boolean.TRUE.toString());
}
}
} Output
|
Hi @krmahadevan ! Thx for Your effort. |
@baflQA - Awesome. Good improvisation there :) Based on your comments, I am closing this issue. |
TestNG Version
7.0.0-beta3
Expected behavior
Dataprovider is skipped when the @BeforeClass configuration method fails, and all the tests are skipped.
Actual behavior
The @BeforeMethod config is skipped, Dataprovider is executed, then the tests are skipped as well.
Maybe dataprovider lacks alwaysRun=true flag?
Running dataproviders when afterClass/Methods are skipped causes some objects to be created but not cleaned up.
Is the issue reproductible on runner?
Test case sample
https://github.com/baflQA/testNG_parallel_debug/blob/37aa3c2822996599cc25a04b03a0cce9ac020879/src/test/java/testngparallel/Class1.java
Please run the "test1" test case.
The text was updated successfully, but these errors were encountered: