[英]Run method before each test
Im using testng 6.11
and writing tests in the following test class: 我正在使用
testng 6.11
并在以下测试类中编写测试:
public class MyTest{
public int i;
public void init(){
//initialize i
}
@Test
public void test1(){
//test some
}
@Test
public void test2(){
//Here I need fresh value of i as it would be
//right after invocation of init()
//...
//test something else
}
}
Is it possible to make testng run init()
method before invocation of each test in a test class? 是否有可能在调用测试类中的每个测试之前使testng运行
init()
方法?
Annotate init()
with @BeforeMethod
annotation. 用
@BeforeMethod
注解注释init()
。 See http://testng.org/doc/documentation-main.html#annotations 参见http://testng.org/doc/documentation-main.html#annotations
Sure, your can use the annotation for that 当然,您可以为此使用注释
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run. @BeforeTest:带注释的方法将在运行属于该标记内的类的任何测试方法之前运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.