我想使用 testng 在@BeforeMethod
和@AfterMethod
中打印当前执行测试方法的名称。
喜欢:
public class LoginTest {
@Test
public void Test01_LoginPage(){
//Some Code here
}
@Test
public void Test02_LoginPage(){
//Some Code Here
}
@BeforeMethod
public void beforeTestCase(){
//Print Test method name which is going to execute.
}
@AfterMethod
public void AfterTestCase(){
//Print Test method name which is executed.
}
}
答案 0 :(得分:2)
../../uJ/cerberOS_BSP.h:55:13: error: array type has incomplete element type
extern char cmp_ids[][];
答案 1 :(得分:2)
您可以使用此类link之类的侦听器。链接中的重要代码: -
// This belongs to IInvokedMethodListener and will execute before every method including //@Before @After @Test
public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) {
String textMsg = "About to begin executing following method : " + returnMethodName(arg0.getTestMethod());
Reporter.log(textMsg, true);
}
// This belongs to IInvokedMethodListener and will execute after every method including @Before @After @Test
public void afterInvocation(IInvokedMethod arg0, ITestResult arg1) {
String textMsg = "Completed executing following method : " + returnMethodName(arg0.getTestMethod());
Reporter.log(textMsg, true);
}
// This will return method names to the calling function
private String returnMethodName(ITestNGMethod method) {
return method.getRealClass().getSimpleName() + "." + method.getMethodName();
}
答案 2 :(得分:1)
以下示例说明如何在before方法和After方法中获取@test方法的方法名称和类名
@Test
public void exampleTest(){
}
@BeforeMethod
public void beforemethod(Method method){
//if you want to get the class name in before method
String classname = getClass().getSimpleName();
//IF you want to get the method name in the before method
String methodName = method.getName()
//this will return you exampleTest
}
@AfterMethod
public void beforemethod(Method method){
//if you want to get the class name in After method
String classname = getClass().getSimpleName();
//IF you want to get the method name in the After method
String methodName = method.getName()
//this will return you exampleTest
}