【发布时间】:2014-03-19 05:59:28
【问题描述】:
有什么方法可以在@Test 上赋予@BeforeMethod 的依赖关系,因为在我的场景中,不同的TestMethod 有不同的设置,而我需要一个依赖于TestMethod 的设置。我在这里添加一些代码 sn-p 以便更好地理解
@BeforeMethod(groups = {"gp2"})
public void setUp1() {
System.out.println("SetUp 1 is done");
}
@BeforeMethod(groups = {"gp1"}, dependsOnGroups = {"tgp1"})
public void setUp2() {
System.out.println("SetUp 2 is done");
}
@Test(timeOut = 1, groups = {"tgp1"})
public void testMethod() throws InterruptedException {
Thread.sleep(2000);
System.out.println("TestMethod() From Group1");
}
@Test(dependsOnMethods = {"testMethod"}, groups = {"tgp2"})
public void anotherTestMethod() {
System.out.println("AnotherTestMethod()From Group1 and Group2");
}
输出
设置 1 已完成 设置 2 完成
但我需要 setUp1() 而不是 setUp2() 因为它取决于 tgp1 组。
我观察到的另一件事是,如果我从
更改依赖项@BeforeMethod(groups = {"gp1"}, dependsOnGroups = {"tgp1"})
到
@BeforeMethod(groups = {"gp1"}, dependsOnMethods = {"testMethod"})
然后我得到一个异常
setUp2() is depending on method public void testMethod() throws java.lang.InterruptedException, which is not annotated with @Test or not included.
我需要执行的应该是这个步骤
SetUp1---->testMethod1()-------->SetUp2--------->testMethod2()
我需要这个,因为不同的 TestMethod 有不同的工作,它有不同的 SetUp()。
【问题讨论】:
-
你能解释一下你想用这个依赖实现什么吗?如果您可以添加测试启动方式的配置或说明,也会有所帮助。
标签: java unit-testing selenium-webdriver testng