繁体   English   中英

每次测试前运行方法

[英]Run method before each test

我正在使用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
    }
}

是否有可能在调用测试类中的每个测试之前使testng运行init()方法?

@BeforeMethod注解注释init() 参见http://testng.org/doc/documentation-main.html#annotations

当然,您可以为此使用注释

@BeforeTest:带注释的方法将在运行属于该标记内的类的任何测试方法之前运行。

您可以使用@BeforeMethod注释在每次测试之前执行任何方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM