testng - 无法从测试组中读取 TestNG 类组
问题描述
我有以下代码来读取测试用例组以进行报告:
public void MethodSetup(ITestContext context, Method testMethod) {
log.info("CLEAR_OUTPUT");
Test t = testMethod.getAnnotation(Test.class);
testCaseGroups = t.groups();
// log.info(t.groups()[0]);//or however you want to use it.
}
当我对测试用例进行分组时,这非常有效,例如
@Test(Groups = "G1")
public void testCase1()
{}
但是当我在类级别定义组并抛出空指针时它不起作用。
@Test(Groups="G1")
public class SampleClassTest
{
@Test(Groups = "G3")
public void testCase1()
{
}
}
我试图搜索谷歌,但找不到任何解决这个问题的方法。谁能帮我解决这个问题。
解决方案
您在该测试类中是否还有其他没有 @Test 注释的方法?
如果是这样,那么当您使用 @Test 注释标记类时,只有该类具有注释,而不是方法。
所以如果你有这样的测试课
@Test(groups="G1")
class TestClass {
// this test method has no annotation,
// but it will run by TestNG because it is public
// and the class has @Test annotation
public void testMethod1(){...}
// this test method would have its own @Test annotation
@Test(groups="G2")
public void testMethod2(){...}
}
然后你会在通过MethodSetup
时抛出异常。testMethod1
编辑:
如果您获得没有@Test
注释的方法,您可以检索类级@Test
注释并获取它的组。
推荐阅读
- mysql - 从 CSV 加载到 MySQL 表时,MySQL 中的双/十进制工资值的数据截断问题
- ajax - 在从 java 脚本进行 Ajax 调用之前在 Asp.Net Core 中进行模型验证
- c# - 计算 Windows 10 上第 3 方窗口的标题栏按钮的总宽度
- c# - 为什么要绑定列表
到 ListView 文本框不保存更改,尽管双向模式 - reactjs - 错误:一个沉浸式生产者返回了一个新值*并*修改了它的草稿。返回一个新值*或*修改草稿
- javafx - 在 JavaFx 和场景构建器中包含 WebView 组件时出错
- nvidia - 是否可以将 INT8 输入层用于 tensorrt?
- android - 用户交互能否在 OnResume 完成之前触发事件?
- amp-html - 根据地理位置重定向 AMP 页面
- c# - 如何在 Xamarin 中使用 BindingContext