以下を取ってを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()
:
「メソッドメソッド= result.getMethod()。getConstructorOrMethod()。getMethod();」を使用しました。これは私のために働いた。ありがとう! –