有没有什么办法让依赖于@BeforeMethod上@测试,因为在我的情况不同TestMethod的有不同的设置,我需要一个设置取决于TestMethod的。 我在这里添加一些代码片断以便更好地理解
@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");
}
产量
SETUP 1完成设置2完成
但我需要设置1()应执行不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.
我需要执行应该在这个步骤
设置1 ----> testMethod1()------->设置2 ---------> testMethod2()
我需要这个,因为不同TestMethods有不同的工作,它有不同的设置()。