2016-04-18 5 views
0

以下を取ってをTestNG Listenerに入れます。私は@BeforeClassと同等のものをonBeforeClass(ITestClass, IMethodInstance)と見つけることができました。しかし、@AfterMethodと同等のものは何ですか?TestNG BeforeClassとAfterMethod TestNGリスナーの同等のメソッド

私の目的は、ITestResultをそのメソッドにパラメータとして渡すことです。なぜなら、私はテスト結果を保持しているからです。以下のコードは、テストの注釈とステータスを取得してから、それをテストレールクラウドにプッシュすることを示しています。私が使用してみました:

@Override 
    public void afterInvocation(IInvokedMethod, ITestResult) { 
     .. 
    } 

それは助けにはならなかった。ここで

java.lang.NoSuchMethodException: client.test.reporting.listeners.TestRailListener.test_getVersion() 
    at java.lang.Class.getMethod(Class.java:1670) 

のJava与えた:すべてのメソッドは、何でも多分実行された後、1670年には

throw new NoSuchMethodException(getName() + "." + name + argumentTypesToString(parameterTypes)); 

**@BeforeClass 
     public static void testSetup() throws InterruptedException, IOException, APIException { 
      initTestRail(); 
     } 
@AfterMethod 
public void getStatusAndAnnotation(ITestResult result) throws NoSuchMethodException, IOException, APIException { 
    HashMap<Object, Object> map = new HashMap<>(); 
    Method m = getClass().getMethod(result.getName()); 
    TestCase annotation = m.getAnnotation(TestCase.class); 
    try { 
     map.put("testRailCaseId",annotation.testRailCaseId()); 
    }catch (NullPointerException e){} 
    if (result.isSuccess()) { 
     map.put("result", 1); 
    } else { 
     map.put("result", 5); 
    } 
    if(annotation.testRailDeployEnable() && !map.get("testRailCaseId").equals(null) && !map.get("testRailCaseId").toString().isEmpty()) 
    { 
     TestRailIntegration.addTestResult(map); 
    } 
    else System.out.println("Deploying result was canceled, because test has annotation \"testRailDeployEnable: false\" or \"testRailCaseId\" has no value"); 
}** 

ですステータス(PASS/FAIL/SKIP)、これを実行したいgetStatus AndAnnotation ...()でも、例外/エラーを超えています。すべてのメソッドも実行されているメソッドを含むITestResultオブジェクトを、渡されるなど、onTestFailure()onTestSuccess()onTestSkipped()

答えて

1

は、私はそれが結果に応じて、いくつか持っているafterInvocation()あなたが代わりに単一の方法の、org.testng.ITestListenerを実装することができると思い

@Override public void onTestSuccess(ITestResult iTestResult) { Method method = iTestResult.getMethod().getConstructorOrMethod().getMethod(); Annotation[] annotations = method.getDeclaredAnnotations(); ... }

+0

「メソッドメソッド= result.getMethod()。getConstructorOrMethod()。getMethod();」を使用しました。これは私のために働いた。ありがとう! –

関連する問題