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.
These annotations are used in the same way with any Java-based test framework.
To create a step:
An example:
@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:
Example:
@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();
}
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.
Further reading: