mercredi 10 juillet 2019

TestNG: get a local variable from test method into AfterMethod

I have 100's of tests like this:

@Test
void someTest(){

MyObj obj = doSomething();

// test continues here

}

Now I need to add some cleanup, but I need a value stored in the obj. Can I retrieve it somehow in AfterMethod or AfterClass WITHOUT having to modify all of my tests? Meaning:

@AfterMethod
void cleanup(){
  // fetch obj of the test that just finished
}

I've tried inspecting Method and ITestResult objects, but no luck (perhaps I missed it):

@AfterMethod
void cleanup(Method m, ITestResult r){
  // inspected m and r in debug, no luck
}





Aucun commentaire:

Enregistrer un commentaire