Reputation: 313
I am running Junit test using JUnitCore.
And i am trying to use allure framework for reporting.
The documentation suggest to add the AllureRunListener using the JUnitCore.addListener()
.
But, no matter how i try to do so the allure report is coming out empty.
They show the tests that run , and also fail assert, but without the @step,@attachment
.
I tried to search for example of using allure report using the JunitCore and not the maven plugin but couldn’t find anything (Running the test using maven work fine, and allure report everything okay).
How it can be done?
The JunitCore runing -
public static void main(String[] args) {
AllureRunListener allureListener =new AllureRunListener();
JUnitCore core = new JUnitCore();
core.addListener(allureListener);
Result result = core.run(BuildNetworkTest.class);
//Result result = core.runClasses(TestSuite.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
The test -
@Test
public void BuildNetwork(){
try {
Build buildFactory = new Build();
System.out.println("running the BuildNetwork test in TestRunnerPac.BuildNetwork");
StepTemp();
attachmentTemp();
}catch (Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
@Step
public void StepTemp(){
assertThat("stepTemp").isEqualTo("stepTemp");
System.out.println("In stepTemp..");
}
@Attachment
public String attachmentTemp(){
return "this is an attachmentTemp , hope it will work..";
}
Upvotes: 2
Views: 1198
Reputation: 2977
Be sure to launch your tests with the -javaagent argument pointing to aspectjweaver.jar, e.g.:
java -javaagent:"/path/to/aspectjweaver.jar" <the rest of the arguments>
If you're using Maven Surefire plugin, then take a look at the following example on how to do this.
Upvotes: 3