lundi 2 mai 2016

TestNG tests multiple ids (as an array) in a single annotation of Java

I have a TestInfo interface for annotating TestNG tests as below:

public @interface TestInfo {

    /**
     * Test case ID
     */
    public String[] id();

    boolean deploy() default true;

}

In above case, id() is an array of String type (String[ ]). Now my testng tests look like this for example:

@TestInfo(id={"C9114", "C9115"})
@Test 
public class testTrial() {
...something
}

How do I read this annotation array and process each of these ids in a for loop. For instance, I could think of approach like get the test method then...

Method method = result.getMethod().getConstructorOrMethod().getMethod();
TestInfo annotation = method.getAnnotation(TestInfo.class);
int status = 0;
try {
        if (annotation!=null) {
        for(;;/*each id*/){     

                    map.put("id[1]",annotation.id().substring(1));

...... in the next iteration,

            map.put("id[2]",annotation.id().substring(1));

and so on. Syntax is incorrect as this is an example.

Aucun commentaire:

Enregistrer un commentaire