-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GITHUB-2888 - don't fail test with dataProvider if skipped (#2889)
* GITHUB-2888 - don't fail test with dataProvider if skipped
- Loading branch information
1 parent
ebd9dae
commit ff5843a
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
testng-core/src/test/java/test/dataprovider/issue2888/SkipDataProviderListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 static void skipIfSkipMe(ITestNGMethod testNGMethod) { | ||
if (Arrays.asList(testNGMethod.getGroups()).contains("SkipMe")) | ||
throw new SkipException("Test was skipped"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
testng-core/src/test/java/test/dataprovider/issue2888/SkipDataProviderSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package test.dataprovider.issue2888; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Listeners({SkipDataProviderListener.class}) | ||
public class SkipDataProviderSample { | ||
@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"); | ||
} | ||
} |