Reputation: 1071
I've been reading in the Allure wiki however I do not seem to be able to get started with Allure.
I have an IntelliJ project which I use to run JUnit tests with Selenium. I want to add Allure for better feedback after test runs. However I've not been able to understand how Allure would integrate with the rest of my project.
On the wiki page for JUnit it looks like Allure with JUnit only supports maven projects? How can I set up allure to work with an IntelliJ project?
Upvotes: 3
Views: 9290
Reputation: 61
To have allure-results after launching JUnit4 tests from IDE using context menu or controls on the gutter I use @RunWith anntotation where I set my custom runner with AllureJUnit4 listener.
CustomRunner class
package ru.atconsulting.qa.system.junit4runners;
import io.qameta.allure.junit4.AllureJunit4;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
public class CustomRunner extends BlockJUnit4ClassRunner {
/**
* Creates a BlockJUnit4ClassRunner to run {@code klass}
*
* @param klass
* @throws InitializationError if the test class is malformed.
*/
public CustomRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
public void run(RunNotifier notifier) {
notifier.addListener(new AllureJunit4()); //just add listener
super.run(notifier);
}
}
Using @RunWith annotation in test classes
@RunWith(CustomRunner.class)
public class ExampleSuite {
@Test
public void testExample() {
....
}
}
Upvotes: 0
Reputation: 1183
I want to add Allure for better feedback after test runs
It is strange that you don't have a build tool. But for single test (as you mention) following will work.
Dependencies - you need aither allure-junit-adaptor or allure-testng-adaptor
Allure implements test listener, which should be added to test runner:
public static void main(String[] args) { JUnitCore runner = new JUnitCore(); runner.addListener(new AllureRunListener()); runner.run(CalculatorTest.class); }
That will generate XML report in target/allure-results folder.
If you need advanced Allure features like file attachments and test steps you need another dependency (aspectjweaver) and according JVM args, e.g.
-javaagent:lib/aspectjweaver-1.8.7.jar
To generate HTML report from existing XML report you can:
Open your HTML report in Firefox (or look here how to open locally generated report in Chrome).
Upvotes: 4