1

Unable to call custom annotation in selenium test i am writing a Apache poi selenium junit test - To avoid @RunWith i have tried myown annotation

public class MyTest extends OtherTest {
    String a ;
    String b;
    String c;
    String d;

   @testDataProvider(name = "abc")
    public static Object[][] fetchClass(){
        Object[][] ar = excel.getar("abc");
        return (ar);
    }

    @testDataProviderTest(dataProvider = "abc")
    @Test
    public void test1() {
        System.out.println(a);
    }

Custom annotation class for testDataProvider, I have tried to use same testng DataProvider in the Custom annotation as below

 @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface testDataProvider {
    public String name() default "";
    boolean parallel() default false;
    int[] indices() default {};
}

Custom annotation for testDataPrviderTest

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD,ElementType.CONSTRUCTOR,ElementType.TYPE})
public @interface testDataProviderTest {
    public String[] groups() default {};
    public boolean enabled() default true;
    @Deprecated
    public String[] parameters() default {};
    public String[] dependsOnGroups() default {};
    public String[] dependsOnMethods() default {};
    public long timeOut() default 0;
    public long invocationTimeOut() default 0;
    public int invocationCount() default 1;
    public int threadPoolSize() default 0;
    public int successPercentage() default 100;
    public String dataProvider() default "";
    public Class<?> dataProviderClass() default Object.class;
    public boolean alwaysRun() default false;
    public String description() default "";
    public Class[] expectedExceptions() default {};
    public String expectedExceptionsMessageRegExp() default ".*";
    public String suiteName() default "";
    public String testName() default "";
    public boolean sequential() default false;
    public boolean singleThreaded() default false;
    public Class retryAnalyzer() default Class.class;
    public boolean skipFailedInvocations() default false;
    public boolean ignoreMissingDependencies() default false;
    int priority() default 0;

}

I am avoiding to use @RunWith as I have Before method to fetch the path of Excel sheet.

1
  • Can you explain what is your final goal? What does make you think this annotation should work? JUnit doesnt pick just any annotation to define which method provides data for tests. It expects the annotation of strictly defined type.
    – Alexey R.
    Nov 19 '18 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.