2016-05-03 11 views
0

の単一の注釈に(配列のような)複数のIDをテスト:上記の場合TestNGのは、私は以下のようにTestNGのテストに注釈を付けるTestInfoインタフェースを有するジャワ

public @interface TestInfo { 

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

    boolean deploy() default true; 

} 

、ID()は、文字列型の配列であります(String [])。今私のTestNGのテストでは、例えば次のようになります。

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

は、どのように私はこれらのidsの各ループの中にこの注釈アレイとプロセスを読んでください。私は、テストに関連したIDのIDと結果を格納しようとしているとして、私は...例えば、私はその後get the test method注釈のようなアプローチを考える可能性があり、以下に示すように、各IDの確認...

Map<Object, Object> map = new HashMap<Object, Object>(); 
     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",annotation.id().substring(1)); 

        switch (status) { 
        case ITestResult.SUCCESS: 
         map.put("result", STATUS.PASSED.getValue()); 
        case ITestResult.FAILURE: 
         map.put("result", STATUS.AUTO_FAIL.getValue()); 
        case ITestResult.SKIP: 
         map.put("result", STATUS.AUTO_SKIPPED.getValue()); 
        default: 
         map.put("result", STATUS.UNTESTED.getValue()); 
        } 
        ApiIntegration.addTestResult(map); 

      } 
} 

それを行う正しい方法は何ですか?

答えて

0

私が正しくあなたを理解していれば、質問はデータ構造にあるのですか?

その場合、あなたはcom.google.common.collect.ListMultimap

ListMultimap<String, String> map = ArrayListMultimap.create(); 
    for (String id : annotation.ids()) { 
     map.put(ITestResult.SUCCESS, id); 
    } 

    // getting all passed 
    List<String> passedTestIds = map.get(ITestResult.SUCCESS); 
グァバを使用することができます
関連する問題