Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to retry a data provider during failures
Closes #2819
- Loading branch information
1 parent
8b70f6f
commit f3bc377
Showing
16 changed files
with
411 additions
and
103 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
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
21 changes: 21 additions & 0 deletions
21
testng-core-api/src/main/java/org/testng/IRetryDataProvider.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,21 @@ | ||
package org.testng; | ||
|
||
/** Represents the ability to retry a data provider. */ | ||
public interface IRetryDataProvider { | ||
|
||
/** | ||
* @param dataProvider - The {@link IDataProviderMethod} object which represents the data provider | ||
* to be invoked. | ||
* @return - <code>true</code> if the data provider should be invoked again. | ||
*/ | ||
boolean retry(IDataProviderMethod dataProvider); | ||
|
||
/** A dummy implementation which disables retrying of a failed data provider. */ | ||
class DisableDataProviderRetries implements IRetryDataProvider { | ||
|
||
@Override | ||
public boolean retry(IDataProviderMethod dataProvider) { | ||
return false; | ||
} | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
testng-core/src/main/java/org/testng/internal/FilteredParameters.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,62 @@ | ||
package org.testng.internal; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
import org.testng.ITestNGMethod; | ||
import org.testng.TestNGException; | ||
|
||
class FilteredParameters implements Iterator<Object[]> { | ||
|
||
private int index = 0; | ||
private boolean hasWarn = false; | ||
private final Iterator<Object[]> parameters; | ||
private final ITestNGMethod testMethod; | ||
private final String dataProviderName; | ||
private final List<Integer> indices; | ||
|
||
public FilteredParameters( | ||
Iterator<Object[]> parameters, | ||
ITestNGMethod testMethod, | ||
String dataProviderName, | ||
List<Integer> indices) { | ||
this.parameters = parameters; | ||
this.testMethod = testMethod; | ||
this.dataProviderName = dataProviderName; | ||
this.indices = indices; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
if (index == 0 && !parameters.hasNext() && !hasWarn) { | ||
hasWarn = true; | ||
String msg = | ||
String.format( | ||
"The test method '%s' will be skipped since its " | ||
+ "data provider '%s' " | ||
+ "returned an empty array or iterator. ", | ||
testMethod.getQualifiedName(), dataProviderName); | ||
Utils.warn(msg); | ||
} | ||
return parameters.hasNext(); | ||
} | ||
|
||
@Override | ||
public Object[] next() { | ||
testMethod.setParameterInvocationCount(index); | ||
Object[] next = parameters.next(); | ||
if (next == null) { | ||
throw new TestNGException("Parameters must not be null"); | ||
} | ||
if (!indices.isEmpty() && !indices.contains(index)) { | ||
// Skip parameters | ||
next = null; | ||
} | ||
index++; | ||
return next; | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new UnsupportedOperationException("remove"); | ||
} | ||
} |
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
Oops, something went wrong.