鉴于具有数据提供者和Allure的TestNG测试类用于报告,需要根据数据提供者修改Allure的报告以具有(@Test(description),@ TmsLink,@ Description)值。
有简单的方法吗?
注意:我尝试使用ITest界面更改测试名称,但对Allure报告无效,我需要TestNG测试说明并修改Allure @Decription和@TmsLink值。
@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;
}
[我设法更改了Allure @Description
和@TmsLink
以及TestNG @Test.description
,但在更改之前Allure仍然获得了TestNG @Test.description
,因此我需要在Allure捕获它之前更新@ Test.description。