forked from testng-team/testng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle exceptions from data provider
Closes testng-team#2157
- Loading branch information
1 parent
ef05341
commit eb8144d
Showing
5 changed files
with
83 additions
and
0 deletions.
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
11 changes: 11 additions & 0 deletions
11
src/main/java/org/testng/DataProviderInvocationException.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,11 @@ | ||
package org.testng; | ||
|
||
/** | ||
* Represents any issues that arise out of invoking a data provider method. | ||
*/ | ||
public class DataProviderInvocationException extends TestNGException { | ||
|
||
public DataProviderInvocationException(String string, Throwable t) { | ||
super(string, t); | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
src/test/java/test/dataprovider/issue2157/TestClassWithDataProviderThatThrowsExceptions.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,50 @@ | ||
package test.dataprovider.issue2157; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.testng.Assert; | ||
import org.testng.IRetryAnalyzer; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestClassWithDataProviderThatThrowsExceptions { | ||
|
||
@Test(dataProvider = "dp", retryAnalyzer = SimplyRetry.class) | ||
public void testMethod(String i) { | ||
if ("First".equalsIgnoreCase(i) || "Second".equalsIgnoreCase(i)) { | ||
Assert.fail(); | ||
} | ||
} | ||
|
||
private static AtomicInteger counter = new AtomicInteger(); | ||
|
||
@DataProvider(name = "dp") | ||
public static Object[][] dpWithException() { | ||
return new Object[][]{ | ||
{foo()}, | ||
}; | ||
} | ||
|
||
private static String foo(){ | ||
counter.getAndIncrement(); | ||
|
||
if(counter.get() == 1){ | ||
return "First"; | ||
} | ||
if(counter.get() == 2){ | ||
return "Second"; | ||
} | ||
throw new RuntimeException("TestNG doesn't handle an exception"); | ||
} | ||
|
||
public static class SimplyRetry implements IRetryAnalyzer { | ||
|
||
private static int attempts = 1; | ||
|
||
@Override | ||
public boolean retry(ITestResult result) { | ||
return attempts++ != 3; | ||
} | ||
} | ||
|
||
} |