Java 如何根据数据提供程序提供的测试参数修改TestNG/Allure(@Test(description),@description,@TmsLink)值
给定一个带有dataProvider和Allure用于报告的TestNG测试类,需要修改Allure的报告,使其具有(@test(description)、@TmsLink、@description)值,具体取决于dataProvider 有简单的方法吗 注: 我尝试使用ITest接口更改测试名称,但对Allure报告没有影响,我需要修改TestNG测试描述和Allure@Decription和@TmsLink值。Java 如何根据数据提供程序提供的测试参数修改TestNG/Allure(@Test(description),@description,@TmsLink)值,java,reflection,testng,allure,testng-dataprovider,Java,Reflection,Testng,Allure,Testng Dataprovider,给定一个带有dataProvider和Allure用于报告的TestNG测试类,需要修改Allure的报告,使其具有(@test(description)、@TmsLink、@description)值,具体取决于dataProvider 有简单的方法吗 注: 我尝试使用ITest接口更改测试名称,但对Allure报告没有影响,我需要修改TestNG测试描述和Allure@Decription和@TmsLink值。@BeforeMethod(alwaysRun=true) @BeforeMeth
@BeforeMethod(alwaysRun=true)
@BeforeMethod(alwaysRun = true)
public void BeforeMethod(Method method, Object[] testData){
TmsLink tmsLink = method.getAnnotation(TmsLink.class);
Description description = method.getAnnotation(Description.class);
Test test = method.getAnnotation(Test.class);
changeAnnotationValue(tmsLink, "value", "<GET FROM testData>");
changeAnnotationValue(description, "value", "<GET FROM testData>");
changeAnnotationValue(test, "description", "<GET FROM testData>");
}
@SuppressWarnings("unchecked")
public static Object changeAnnotationValue(Annotation annotation, String key, Object newValue){
System.out.println("BEFORE annotation: " + annotation);
Object handler = Proxy.getInvocationHandler(annotation);
Field f;
try {
f = handler.getClass().getDeclaredField("memberValues");
} catch (NoSuchFieldException | SecurityException e) {
throw new IllegalStateException(e);
}
f.setAccessible(true);
Map<String, Object> memberValues;
try {
memberValues = (Map<String, Object>) f.get(handler);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
Object oldValue = memberValues.get(key);
if (oldValue == null || oldValue.getClass() != newValue.getClass()) {
throw new IllegalArgumentException();
}
memberValues.put(key,newValue);
System.out.println("AFTER annotation: " + annotation);
return oldValue;
}
public void BeforeMethod(方法,对象[]testData){
TmsLink TmsLink=method.getAnnotation(TmsLink.class);
Description Description=method.getAnnotation(Description.class);
Test=method.getAnnotation(Test.class);
changeAnnotationValue(tmsLink,“值”和“”);
changeAnnotationValue(描述,“值”和“);
changeAnnotationValue(测试,“描述”和“);
}
@抑制警告(“未选中”)
公共静态对象changeAnnotationValue(注释注释、字符串键、对象newValue){
System.out.println(“注释前:”+注释);
对象处理程序=Proxy.getInvocationHandler(注释);
字段f;
试一试{
f=handler.getClass().getDeclaredField(“memberValues”);
}catch(NoSuchFieldException | SecurityException e){
抛出新的非法状态异常(e);
}
f、 setAccessible(true);
映射成员值;
试一试{
memberValues=(Map)f.get(handler);
}捕获(IllegalArgumentException | IllegalAccessException e){
抛出新的非法状态异常(e);
}
对象oldValue=memberValues.get(键);
如果(oldValue==null | | oldValue.getClass()!=newValue.getClass()){
抛出新的IllegalArgumentException();
}
memberValues.put(key,newValue);
System.out.println(“注释后:“+注释”);
返回旧值;
}
我设法更改了诱惑
@Description
和@TmsLink
以及TestNG@Test.Description
,但诱惑在更改之前仍然会得到TestNG@Test.Description
,所以我仍然需要在诱惑捕获它之前更新@Test.Description。您找到了解决此问题的方法吗?