Skip to content

Ability to retry a data provider during failures#2820

Merged
krmahadevan merged 1 commit intotestng-team:masterfrom
krmahadevan:fix_2819
Nov 3, 2022
Merged

Ability to retry a data provider during failures#2820
krmahadevan merged 1 commit intotestng-team:masterfrom
krmahadevan:fix_2819

Conversation

@krmahadevan
Copy link
Copy Markdown
Member

Closes #2819

Fixes #2819 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

Sample test case

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class TestClassUsingDataProviderRetrySample {

  private int counter = 0;

  @Test(dataProvider = "dp")
  public void sampleTest(int ignored) {}

  @DataProvider(name = "dp", retryUsing = SimpleRetry.class)
  public Object[][] getTestData() {
    if (counter++ < 2) {
      throw new RuntimeException("Simulating a failure");
    }
    return new Object[][] {{1}};
  }
}

Sample retry mechanism implementation

import org.testng.IDataProviderMethod;
import org.testng.IRetryDataProvider;

public class SimpleRetry implements IRetryDataProvider {

  private int counter = 0;

  @Override
  public boolean retry(IDataProviderMethod dataProvider) {
    return counter++ < 2;
  }
}

@krmahadevan krmahadevan requested a review from juherr as a code owner November 3, 2022 10:43
@krmahadevan krmahadevan merged commit f3bc377 into testng-team:master Nov 3, 2022
@krmahadevan krmahadevan deleted the fix_2819 branch November 3, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to retry a data provider in case of failures

2 participants