【背景】
随着用例数目增多,不同类型的用例需要的初始化步骤不同,想通过 groups 配合 beforeMethod 来区分初始化工作。
不想通过类来管理,用例组织不太好看。--- 大家暂且忽略这个方案
尝试对 beforeMethod 标签化,未能生效,群里大牛帮忙答疑~~~ 😁😁😁😁

【代码】

// test case 1
@Test(groups = {"reset"})
public void testCase1() {
    System.out.println("in test case 1");
}

// test case 2
@Test
public void testCase2() {
    System.out.println("in test case 2");
}

@BeforeMethod(groups = {"reset"}, alwaysRun = false)
public void beforeMethod1() {
    System.out.println("in beforeMethod1-reset");
}

@BeforeMethod
public void beforeMethod2() {
    System.out.println("in beforeMethod2");
}

【期望结果】
testCase1 调用 beforeMethod1 初始化
testCase2 调用 beforeMethod2 初始化

【实际结果】

in beforeMethod1-reset
in beforeMethod2
in test case 1
in beforeMethod1-reset
in beforeMethod2
in test case 2

两个 beforeMethod 均被用例调用,未能达到期望的效果


↙↙↙阅读原文可查看相关链接,并与作者交流