Configure report generation HTML template in Maven Surefire Java for JUnit - junit4

I am working on Selenium automation using Java. I am using Maven automation and maven surefire dependency to generate HTML reports of JUnit tests. Default format looks great. But I want to configure HTML format and want Surefire to render my custom HTML format. I tried some options along with "mvn surefire-report:report-only" but those are not working.
mvn execution commands I am using are as follows:
mvn test
mvn surefire-report:report-only
mvn site
-DgenerateReports=false
Can you please guide me.

Run surefire-report:report maven goal on your project. This will generate an HTML file under {project_location}/target/site/surefire-report.html.
mvn surefire-report:report
See https://maven.apache.org/surefire/maven-surefire-plugin/usage.html for more details.

Related

Eclipse's embedded Maven doesn't accept run-time arguments

I have configured jar.version as dynamic input to pom.xml
<artifactId>xyz</artifactId>
<version>${jar.version}</version>
I tried to configure maven goal in eclipse's run configuration as
clean install -Djar.version=1.0.1
I also tried to add jar.version=1.0.1 in parameter section of maven run configuration.
But this parameter is not accessible by maven build process. Need help here.
I am able to access it if i use external maven (and not eclipse's embedded one) then below command works well
mvn clean install -Djar.version=1.0.1

Spock script not compiling automatically in Spring MVC project which is using Eclipse IDE

I am working on a Spring based web project (Eclipse as IDE), in which we want to introduce integration testing framework using Spock. This project is based on Maven. For this purpose I have installed Greclipse plugin and converted the existing project to groovy nature. Also configured Maven to run the test classes in src/test/groovy folder, and everything working fine and all the spock tests are running fine with run "Maven test" phase. Configured the build path to compile the groovy test files to target/test-classes.
The problem is coming when I run the Spock tests using Run -> Run configuration. It runs file with Junit runner using run configuration, it is picking up the compiled test class from target/test-classes. Whenever I modify the Spock test script file, it is not automatically generating the classes, Run with Run Configuration is always picking up the old compiled class.
How to force the script to compile so that I don't always need to Maven clean and Maven test, to force it compile and run.
I have found in some other threads talking about modifying the Groovy compiler options to "Enable script folder Support", both checking and unchecking is of no use either. Its not forcing the Spock script to compile (also tried enabling the same option in Eclipse Preferences global Groovy compiler option)
Any help is greatly appreciated.
Spock tests are implemented as a class extending Specification. So they are treated like any other Groovy class.
If in Eclipse under "Project" → "Build Automatically" is enabled, Eclipse compiles the classes automatically on every change. So if you change a Spock test in Eclipse, running it should always use the newest compiled version.
For automatic compilation to work correctly, the source has to be configured properly in Eclipse. Check via "Configure Build Path..." on your Eclipse project that under the "Source" tab the src/test/groovy/ folder is configured correctly.

Cucumber and Eclipse IDE; How to make jar for a test case

I'm a Cucumber and Eclipse beginner and have a few questions and hope you can help me to get through this: I created a sample cucumber test scenario, a sample test steps and a cucumber runner. The scenarios runs fine within eclipse IDE (Neon). I used Maven as the dependency manager. I also installed the Maven command line module. The step code is Java.
Here is the (basic) question: How do I create a jar file from my cucumber test scenario so that execute it via command line so that I can bring the test scenario to Jenkins CI? Is there anything I need to do with Maven BEFORE I can build the jar file?
Thanks a lot folks!
If you run Cucumber using the JUnit runner, then all you have to do to run from a command line is to execute Maven and make sure you invoke a life cycle phase that includes running the unit tests. One way would be
mvn test
An example that might get you up and running can be found at
https://github.com/cucumber/cucumber-java-skeleton

Aggregate surefire reports of maven project hierarchy as XML for eclipse?

I have a project hierarchy which built with maven. How can I run all the tests in the whole hierarchy at once from eclipse and easily go to the failures?
The maven surefire plugin spews loads of output at the console, but it is tiresome to find the failures there. It also generates XML report files which I can easily open within the normal eclipse JUnit view - but these are many many files and it is difficult to find the files of the failed tests. The maven surefire report plugin allows to aggregate all test results with mvn surefire-report:report-only -Daggregate=true but only in HTML format. What I'd love to have is an aggregation of all test results in the eclipse JUnit view - just as I get if I use "Run as JUnit-Test".
(Ideally, I would start all the unittests with "Run as JUnit-Test", but I can do that only for one project, not for all the projects in the workspace.)

m2eclipse filtering test resources

I am using m2eclipse and I want to right click and run tests from inside eclipse while the test resources get filtered from Maven. How can I do this? From eclipse when I right click on a test I do not get any m2eclipse options
Julia.
Similar to:
Debugging maven junit tests with filtered resources?
Setup filtering in your pom.xml (and you'll get filtering under Eclipse with m2eclipse, m2eclipse runs process-resources after a change of any resource).
Run your test as any other test (right-click then Run As > JUnit Test).
After a first run, you can run an individual test method (right-click on the method in the JUnit view).
Right click on the project -> Run As -> Maven test