Issue
I have a large number of Junit tests running selenium on eclipse, what I would like to do is generate a Junit or surefire report for the tests after all of them are run. I know that with maven you can do this for individual tests by running mvn test on the console and generating a report with:
mvn surefire-report:report-only
However, this tests and produces a report for each individual test, is there a way to make this work for multiple tests? The reason behind this is because I run these tests headlessly on Jenkins, I know that jenkins email plugin can allow me to pass a html report post build which would give me an idea of test success and failure.
Solution
Firstly you need to have all the right plugins and dependencies in your pom.xml file.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
<!-- `mvn clean test site` to generate the junit html report-->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</reporting>
Following this add the maven command to your maven build as shown.
After you run this your IDE will run all the tests in that maven build and generate a surefire.html report which can be found in target/site/surefire-report.html (You may need to update your maven project to see the folder come up for the first time by right clicking the project, then hover over maven and then click update maven project.)
I would advise doing this as it then works with jenkins when it runs your tests in headless mode which can then be attached to your email extension plugin.
Answered By - Oren Berreby
Answer Checked By - Mildred Charles (JavaFixing Admin)