TestNG: Identifying which tests methods are next

ε祈祈猫儿з 提交于 2019-12-06 12:11:29

I don't know about any easy way to get next test method. BTW, you can achieve the same result using @AfterGroups annotation:

@Test(groups = {"groupA"})
public void testA(...) { ... }

@Test(groups = {"groupB"})
public void testB(...) { ... }

@AfterGroups(groups = {"groupA"})
public void afterGroupA() {
    // clear entity manager here
}

Note, that order of tests starting is not guaranteed by TestNG, until you specify it explicitly with dependsOnMethods or dependsOnGroups parameters of @Test annotation, or "preserve-order" attribute of tag in testng.xml file.

UPDATE

As an alternative you can use your own TestListiner. You can implement onTestStart() method, which will do clearing, if it is necessary. AFAIU, invoked test method is available in partially filled ITestResult. BTW, be careful - this may lead to problems caused by implicit test logics (clearing will not be visible from test code).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!