魅力框架:将@Step和@Attachment批注与TestNG和Maven结合使用 [英] Allure Framework: using @Step and @Attachment annotations with TestNG and Maven
问题描述
我正在一个使用Java,TestNG和Maven的 Allure框架的项目. 但是在我的Java程序中使用Allure @Step和@Attachment批注时,我无法生成正确的XML文件.任何演示上述注释用法的示例代码都将受到赞赏. 我正在使用Allure 1.4.0.RC8.
I am working on a project that uses Allure framework with Java, TestNG and Maven. But I'm unable to generate correct XML files while using Allure @Step and @Attachment annotations in my Java program. Any sample code demonstrating usage of the above annotations is appreciated. I am using Allure 1.4.0.RC8.
推荐答案
这些注释与基于Java的任何测试框架都以相同的方式使用.
These annotations are used in the same way with any Java-based test framework.
创建步骤:
- 使用具有步骤逻辑的可见性修饰符(公共,私有,受保护)创建方法,并使用@Step注释对其进行注释.您可以选择在注释属性中指定步骤名称.
- 在测试方法中调用此方法.
一个例子:
@Test
public void someTest() throws Exception {
//Some code...
stepLogic();
//Some more assertions...
}
@Step("This is step 1")
private void step1Logic() {
// Step1 implementation
}
@Step("This is step 2")
private void step2Logic() {
// Step2 implementation
}
要创建附件,请执行以下操作:
To create an attachment:
- 创建具有可见性的方法,该方法可以返回 byte [] -附件内容,并使用 @Attachment 注释对其进行注释.
- 在任何测试中调用此方法
- Create method with any visibility which return byte[] - attachment contents and annotate it with @Attachment annotation.
- Call this method inside any test
示例:
@Test
public void someTest() throws Exception {
//Some code...
createAttachment();
//Some more assertions...
}
@Attachment(name = "My cool attachment")
private byte[] createAttachment() {
String content = "attachmentContent";
return content.getBytes();
}
为了使 @Step 和 @Attachment 批注起作用,您需要在配置中正确启用AspectJ.这通常是通过指向 aspectj-weaver.jar 文件的 -javaagent JVM参数完成的.
In order to make @Step and @Attachment annotations work you need to correctly enable AspectJ in your configuration. This is usually done via -javaagent JVM argument pointing to aspectj-weaver.jar file.
进一步阅读:
- Using with TestNG
- Steps
- Attachments
这篇关于魅力框架:将@Step和@Attachment批注与TestNG和Maven结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!