組運行時不計算組配置。 test
方法將不會激活setupForGroupA
方法。
該功能用於查找要運行的方法。 根據下面的例子:
@BeforeMethod(groups = "a")
public void setupForGroupA() {
...
}
@Test(groups = {"supplemental", "a"})
public void test() {
...
}
@Test(groups = {"supplemental"})
public void test2() {
...
}
如果你運行這個類組「A」,它將運行setupForGroupA
和test
方法,因爲它們都標有「A」組。
如果您使用組「補充」運行此類,它將運行test
和test2
方法,因爲它們標記爲「補充」組。
它看起來對於某些方法有不同的行爲,所以一個好的方法是將不同類中的方法分開,並按類選擇測試,而不是按組來選擇測試。
public class A {
@BeforeMethod
public void setupForGroupA() {
...
}
@Test
public void test() {
...
}
}
和
public class Supplemental {
@Test
public void test2() {
...
}
}
運行類A只會setupForGroupA
和test
運行。 運行類補充將僅運行test2
。運行這兩個類將運行一切。
如果你想運行別的東西兩個類和過濾器,你可以用a method interceptor實現自己的邏輯:
@MyCustomAnnotation(tags = "a", "supplemental")
public class A {
...
}
@MyCustomAnnotation(tags = "supplemental")
public class Supplemental {
...
}
public class MyInterceptor implements IMethodInterceptor {
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
// for each method, if its class contains the expected tag, then add it to the list
// expect tag can be passed by a system property or in a parameter from the suite file (available from ITestContext)
}
}
所以擴大的例子有點我可以用組添加一個方法「測試2」補充,但沒有組「a」。在這種情況下,我希望before方法在'test'之前運行,但不要在'test2'之前運行。 – RankWeis