mardi 19 février 2019

Find parametrised method in unit test through reflection

I have a Below sample code where I am trying to read the testid in after method , for method without parameters it works well , but My methods have Map as a parameter ..and it is failing. I am not able to figure out how to read this testid in Aftermethod for parametrized method.-

Also In testng if say test1 failed then test2 will be skipped due to dependonMethod how can i still read this skipped method annotation value in aftermethod??

@Data(testId = 1623)
@Test(description = "test 1")
public void readTestAnnotation(Map<String,String> inputData) {
    logger.assertTrue(true, " test pass");
    logger.assertAll();
}


@Data(testId = 1645)
@Test(dependsOnMethods= {"readTestAnnotation"},  description = "test 
2")
public void readTestAnnotation1(Map<String,String> inputData) {
    logger.assertTrue(true," test failed");
    logger.assertAll();
}


@Data(testId = 1646)
@Test(dependsOnMethods = {"readTestAnnotation1"}, description = 
"test3")
public void readTestAnnotation2(Map<String,String> inputData) {
    logger.assertTrue(true," test failed");
    logger.assertAll();
}


 @AfterMethod(alwaysRun = true)
public void readtestId(ITestResult tr) throws NoSuchMethodException, 
SecurityException {
String methodName = tr.getMethod().getMethodName();
UseAsTestId ta = 
sampletest.class.getMethod(methodName).
   getAnnotation(UseAsTestRailId.class);

    System.out.println(ta.testRailId());

 }





Aucun commentaire:

Enregistrer un commentaire