【发布时间】:2016-01-08 17:27:04
【问题描述】:
问题陈述:我有多个具有@BeforeMethod 和@Test 方法的testng 类,并且一些测试是通过另一种测试方法调用的。在这种情况下,BeforeMethod 方法不会被执行。
例如
public class A {
@BeforeMethod
public void preCheck(){
System.out.println("Pre-Check A");
}
@Test
public void check(){
System.out.println("Check A");
B objB = new B();
objB.check();
}
}
public class B {
@BeforeMethod
public void preCheck(){
System.out.println("Pre-Check B");
}
@Test
public void check(){
System.out.println("Check B");
}
}
当我将 A 类作为 Testng 类执行时,我得到以下输出
Pre-Check A
Check A
Check B
而期望的输出是
Pre-Check A
Check A
Pre-Check B
Check B
我怎样才能达到同样的效果?
【问题讨论】:
-
你应该创建一个对象层次结构。
-
尝试使用testng.xml文件调用
标签: java annotations testng