如何拥有我的";config()";每个testng会话只运行一次



我有多个testNG类,用于测试我们网站的不同功能。对于每个类,在执行之前,都需要运行相同的config((调用来设置一些设备。

因此,对于每个单独的测试类,它看起来是这样的格式:

public class TestFeature1 extends TestEnvironment {
@BeforeSuite
@Parameters({ "clusterURL"})
public void config(String clusterURL) throws URISyntaxException {
...
}
...
}

我的问题是,所有这些类可能单独运行,或者在一个testng会话中运行。如果是后面的情况,如何让这个config((只执行一次?目前我正在使用testNG 6.14.3。

将config方法移动到基类,并使用base test扩展所有测试。

public class BaseTest extends TestEnvironment {
@BeforeSuite
@Parameters({ "clusterURL"})
public void config(String clusterURL) throws URISyntaxException {
...
}
...
}
public class TestFeature1 extends BaseTest {
...
}
public class TestFeature2 extends BaseTest {
...
}

最新更新