草帽路飞UU 发表于 2019-4-16 11:51:13

[提问] 关于 testng 的 beforeMethod 标签化问题

看到有人发个帖子,关于如果定制TESTNG报告的,我自己实现过一个自定义的简单报告,所以也就顺便谈谈。

【背景】
随着用例数目增多,不同类型的用例需要的初始化步骤不同,想通过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均被用例调用,未能达到期望的效果
页: [1]
查看完整版本: [提问] 关于 testng 的 beforeMethod 标签化问题