Skip to content
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

GITHUB-2888 - don't fail test with dataProvider if skipped #2889

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-2888: Skipped Tests with DataProvider appear as failed (Joaquin Moreira)
Fixed: GITHUB-2884: Discrepancies with DataProvider and Retry of failed tests (Krishnan Mahadevan)
Fixed: GITHUB-2879: Test listeners specified in parent testng.xml file are not included in testng-failed.xml file (Krishnan Mahadevan)
Fixed: GITHUB-2866: TestNG.xml doesn't honour Parallel value of a clone (Krishnan Mahadevan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,8 @@ public int invoke(int invCount) {
m_configuration.isPropagateDataProviderFailureAsTestFailure()
|| bag.isBubbleUpFailures();

if (throwable instanceof TestNGException || bubbleUpFailures) {
if (!(throwable instanceof SkipException)
&& (throwable instanceof TestNGException || bubbleUpFailures)) {
tr.setStatus(ITestResult.FAILURE);
m_notifier.addFailedTest(arguments.getTestMethod(), tr);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ public void ensureTestNGFailsDueToDataProviderFailure2() {
assertThat(testng.getStatus()).isEqualTo(1);
}

@Test(description = "GITHUB-2888")
public void ensureTestNGSkipExceptionWillSkipTestWithDataProvider() {
TestNG testng = create(test.dataprovider.issue2888.SkipDataProviderTest.class);
testng.propagateDataProviderFailureAsTestFailure();
testng.run();
assertThat(testng.getStatus()).isEqualTo(2);
}

@Test(description = "GITHUB-2255")
public void ensureDataProviderValuesAreVisibleToConfigMethods() {
TestNG testNG = create(test.dataprovider.issue2255.TestClassSample.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package test.dataprovider.issue2888;

import java.util.Arrays;
import org.testng.IDataProviderListener;
import org.testng.IDataProviderMethod;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.SkipException;

public class SkipDataProviderListener implements ITestListener, IDataProviderListener {
@Override
public void onTestStart(ITestResult result) {
skipIfSkipMe(result.getMethod());
}

@Override
public void onTestSkipped(ITestResult result) {}

@Override
public void beforeDataProviderExecution(
IDataProviderMethod dataProviderMethod, ITestNGMethod method, ITestContext iTestContext) {
skipIfSkipMe(method);
}

private void skipIfSkipMe(ITestNGMethod testNGMethod) {
jmoreira18 marked this conversation as resolved.
Show resolved Hide resolved
if (Arrays.asList(testNGMethod.getGroups()).contains("SkipMe"))
throw new SkipException("Test was skipped");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package test.dataprovider.issue2888;

import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import test.SimpleBaseTest;

@Listeners({SkipDataProviderListener.class})
public class SkipDataProviderTest extends SimpleBaseTest {
jmoreira18 marked this conversation as resolved.
Show resolved Hide resolved
@Test(groups = "SkipMe")
public void testSkip() {
Assert.fail("This test should not execute, it should be skipped");
}

@DataProvider(name = "dataProvider")
private Object[][] dataProvider() {
return new Object[][] {new Object[] {"test1"}};
}

@Test(dataProvider = "dataProvider", groups = "SkipMe")
public void testSkipWithDataProvider(String a) {
Assert.fail("This test should not execute, it should be skipped");
}
}