Here’s what should help you get past your predicament.
Here’s a sample that should help you get started.
The custom annotation would look like this.
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention (RetentionPolicy.RUNTIME)
@Target (ElementType.METHOD)
public @interface RowNumber {
String rowNumber () default "";
}
The test code would look like this.
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import rationale.emotions.annotations.RowNumber;
import java.lang.reflect.Method;
public class SampleClass {
private static Object[][] testData = {
{1},
{2},
{3},
{4},
{5}
};
@RowNumber (rowNumber = "2")
@Test (dataProvider = "getData")
public void specialTestMethod (int value) {
System.out.println ("specialTestMethod() Incoming value :" + value);
}
@Test (dataProvider = "getData")
public void ordinaryTestMethod (int value) {
System.out.println ("ordinaryTestMethod() Incoming value :" + value);
}
@DataProvider (name = "getData")
public Object[][] getData (Method method) {
RowNumber rows = method.getAnnotation (RowNumber.class);
if (rows == null) {
return testData;
}
int whichRow = Integer.parseInt (rows.rowNumber ());
return new Object[][] {testData[whichRow-1]};
}
}