[Java] Enable retry in TestNG (#11065)

* Enable retry in Java test

* lint

* update
This commit is contained in:
Kai Yang 2020-09-28 22:16:06 +08:00 committed by GitHub
parent 27e1f513e3
commit 79c6a6fa02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,15 @@
package io.ray.test;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;
public class AnnotationTransformer implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
annotation.setRetryAnalyzer(RetryAnalyzer.class);
}
}

View file

@ -0,0 +1,19 @@
package io.ray.test;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class RetryAnalyzer implements IRetryAnalyzer {
private int counter = 0;
private static final int RETRY_LIMIT = 2;
@Override
public boolean retry(ITestResult result) {
if (counter < RETRY_LIMIT) {
counter++;
return true;
}
return false;
}
}

View file

@ -10,5 +10,6 @@
<listeners>
<listener class-name="io.ray.test.RayAlterSuiteListener" />
<listener class-name="io.ray.test.TestProgressListener" />
<listener class-name="io.ray.test.AnnotationTransformer" />
</listeners>
</suite>