--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/09c6388f-086b-4ed9-8c79-1c3589cd4866n%40googlegroups.com.
public class AnnotationTransformer implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
if (testMethod.getName().contains("test01")) {
System.out.println("The listener is activated for:-" + testMethod.getName());
annotation.setInvocationCount(3);
System.out.println("Invocation count is set to :-" + annotation.getInvocationCount());
}
But it doesn't do anything, I didn't forgot to define this class as Listener in the test class
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/CANikZLkVYx%2B3TUTj9DkfY38pcaiTbfOZoufGHY77%2BUnDkLXK6g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/CAEK7TGro_0qCN42%2B63ygoC83%2BfP14axjK1xc5wJxATYBk-i%2BQg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/c5e230b0-87bc-45c1-90d4-c37881d78fc1n%40googlegroups.com.
import java.util.concurrent.atomic.AtomicInteger;
import org.testng.annotations.Test;
public class SampleTestClass {
public static final AtomicInteger counter = new AtomicInteger(0);
@Test
public void testMethod() {
System.err.println(counter.incrementAndGet());
}
}
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;
public class SimpleTransformer implements IAnnotationTransformer {
public static final String ITERATIONS_COUNT = "iterations.count";
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,
Method testMethod) {
int count = Integer.parseInt(System.getProperty(ITERATIONS_COUNT, "1"));
annotation.setInvocationCount(count);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="sample_suite" verbose="2">
<listeners>
<listener class-name="com.rationaleemotions.dynamic.SimpleTransformer"/>
</listeners>
<test name="sample_test" verbose="2">
<classes>
<class name="com.rationaleemotions.dynamic.SampleTestClass"/>
</classes>
</test>
</suite>
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import org.testng.TestNG;
import org.testng.annotations.Test;
public class TestNGApiRunner {
@Test
public void runTest() {
System.setProperty(SimpleTransformer.ITERATIONS_COUNT, "5");
TestNG testng = new TestNG();
testng.setTestClasses(new Class[]{SampleTestClass.class});
testng.setListenerClasses(Collections.singletonList(SimpleTransformer.class));
testng.run();
assertThat(SampleTestClass.counter.get()).isEqualTo(5);
}
}
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/dc3c5f59-6578-4874-88ef-ae94a3be08b6n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/CANikZLm_Ypy9QrXxq9jFu%3DZwW-yVLbQ6dRKXGkD57uPKw%3D-v5g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-users/CAEK7TGqN8dzWNqef-FOkAWQ%2BD68vw-5rrRN4%3DY6zeXVywWi1RA%40mail.gmail.com.