[英]TestNG one test for two classes
I have TestNG tests in some classes, which extends the same main class. 我在某些类中有TestNG测试,它扩展了相同的主类。 I need the same last test for class1 and class2, but if I add @Test(priority = 666)
to main class it start after all classes. 我需要对class1和class2进行相同的最后一次测试,但是如果我在主类中添加@Test(priority = 666)
,它将在所有类之后开始。 How I should annotate @Test
in main class what would it starts after all tests of each class? 我应该如何注释主类中的@Test
在每个类的所有测试之后它将如何开始?
Big thanks. 太谢谢了。 Also sorry for bad english. 也为英语不好而感到抱歉。
main class 主班
public class MainTest {
@BeforeClass()
public void setup() {
//something
}
@AfterClass()
public void tearDown() {
//something
}
@AfterMethod()
public void log_writer(Method method) {
//something
}
@Test(priority = 666) {}
}
class1 class1的
public class Class1 extends MainTest {
@Test
public void test1(){}
@Test
public void test2(){}
}
and class2 和class2
public class Class2 extends MainTest {
@Test
public void test1(){}
@Test
public void test2(){}
}
what you are looking for is the @AfterClass annotation. 您正在寻找的是@AfterClass批注。 handle the part where you want to check logs in the AfterClass annotated method 在AfterClass带注释的方法中处理您要检查日志的部分
It's not possible. 这是不可能的。 Basically each @Test
runs only once. 基本上每个@Test
只运行一次。 If you need to do something after each test class you have to use @AfterClass
annotation on method in your MainTest
. 如果需要在每个测试类之后执行某些操作,则必须在MainTest
方法上使用@AfterClass
批注。 You can do some hacks with method order etc. in MethodInterceptor ( http://testng.org/doc/documentation-main.html#methodinterceptors ) but it's not good idea for this case. 您可以在MethodInterceptor( http://testng.org/doc/documentation-main.html#methodinterceptors )中对方法顺序等进行一些修改,但这并不是一个好主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.