TestNG - 将自定义属性添加到 @Test 注释 [英] TestNG - Add custom attribute to @Test annotation

查看:43
本文介绍了TestNG - 将自定义属性添加到 @Test 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向现有的 @Test 注释添加一个自定义属性,如下所示.

I need to add a custom attribute to existing @Test annotation like below.

@Test (description = "some description", newAttribute = "some value") 
public void testMethod() {
    // unit/integration test code
}

其中newAttribute"是我添加到@Test 现有属性的新属性.稍后作为报告的一部分,我将读取/删除工作区中此新属性的所有文件,并枚举使用它的测试/方法.

Where 'newAttribute' is the new attribute I have added to existing attributes of @Test. Later as part of reporting, I will read/scrap all files in the workspace for this new attribute and enumerate the tests/methods that use it.

可以用Java完成吗?任何帮助/指针将不胜感激.获取所有使用特定属性/注释的测试的更好方法是什么?

Can it be done in Java? Any help/pointers will be appreciated. Any better way of getting all the tests that use a particular attribute/annotation?

推荐答案

不,没有注解继承这样的东西,因此,如果不重新编译定义注解的库,就不能透明地向兼容类型添加值.但是,您可以向该方法添加另一个注释:

No, there is no such thing as annotation inheritance and therefore, you cannot transparently add a value to a compatible type without recompiling the library that defines the annotation. You can however add another annotation to the method:

@Test (description = "some description") 
@NewAttribute ("some value")
public void testMethod() {
    // unit/integration test code
}

您可以稍后阅读此自定义注释.

You can then read this custom annotation at a later point.

这篇关于TestNG - 将自定义属性添加到 @Test 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆