Cucumber report naming and maven-cucumber-reporting trends - maven

Background info:
Maven version: 3.2.5
Java version: 1.8
Cucumber reporting version: 3.8.0
cucumber-java, cucumber-spring, and cucumber-junit: all version 1.2.5
I have a maven java project. I have cucumber tests and the maven-cucumber-reporting plugin running and working for the project.
Here is how I am running the Cucumber tests:
package com.util.test;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(strict = false, features = "src/test/resources/features", format = {"pretty", "json:src/test/report/cucumber.json"}, tags={"#test, #util"})
public class UtilCucumberTest {
}
And here is my pom with the maven-cucumber-reporting plugin:
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${cucumber.reporting.version}</version>
<executions>
<execution>
<id>testing</id>
<phase>test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.artifactId}</projectName>
<outputDirectory>${project.basedir}/src/test/report/cucumber-reports</outputDirectory>
<cucumberOutput>${project.basedir}/src/test/report/cucumber.json</cucumberOutput>
<skippedFails>true</skippedFails>
<enableFlashCharts>false</enableFlashCharts>
<buildNumber>${project.version}</buildNumber>
</configuration>
</execution>
</executions>
</plugin>
Each time I run a build the cucumber.json file is overwritten and I lose previous build info. I would like to keep a copy of each report (or one per build, as in --report.json). I currently do not see the Trends page either and would like to see this information.
Questions:
What do I need to do to see the Trends information in the pretty HTML report that is generated?
How can I get cucumber to generate a uniquely named .json report file each time I run a build (or one unique report per version build)? And will this allow me to see the trends section comparing previous reports?

Related

How to generate and use a detekt baseline using the maven plugin?

I'm trying to use detekt in a multi-module Maven project using Kotlin with the detekt-maven-plugin.
Following the instructions found here to generate a baseline with the existing issues, I tried running:
mvn detekt:cb -Ddetekt.debug=true
This does not seem to produce the mentioned baseline.xml file however.
Turns out that the baseline filename must be specified when baseline is generated:
mvn detekt:cb -Ddetekt.baseline=baseline.xml
Since the code base already had quite a few issues found by detekt, I also had to use a custom detekt config file and increase the number of allowed issues - otherwise the build would fail and no baseline would be generated at all.
To summarize, the following configuration made it work:
detekt config file:
build:
maxIssues: 1000
Plugin configuration after the baseline was generated:
<plugin>
<groupId>com.github.ozsie</groupId>
<artifactId>detekt-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<baseline>detekt-baseline.xml</baseline>
<config>detekt-config.yml</config>
<buildUponDefaultConfig>true</buildUponDefaultConfig>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
After the baseline was generated, the maxIssuses value in the config file could be lowered to an appropriate value.

How do I re run failed Cucumber scenarios from Maven?

I am trying to re run my failed cucumber tests. I use maven and TestNG in my framework. How can I achieve this?
I have tried maven-surefire-plugin (version: 3.0.0-M3) in my POM with <rerunFailingTestsCount>2</rerunFailingTestsCount>. But this does not rerun the test automatically when a test fails.
POM snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<!-- <suiteXmlFiles>testNG.xml</suiteXmlFiles> -->
<classpathScope>test</classpathScope>
<skipTests>false</skipTests>
<!-- <testFailureIgnore>true</testFailureIgnore> -->
<testSourceDirectory>/src/test/java/testRunners</testSourceDirectory>
<useTestNG>false</useTestNG>
<rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>
</plugin>
Runner class
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features",
glue= {"stepDefinitions"},
tags= {"#licensing01"},
dryRun = false,
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:TestExecutionReports/TestResults.html"
+ ",rerun:TestExecutionReports/failed_scenarios.txt"
+ ",json:target/cucumber.json"},
monochrome = true
)
public class TestRunnerBAU extends AbstractTestNGCucumberTests{
}
I expect the failed tests to be rerun automatically. But currently the failed tests are not rerun.
As Per Maven Guideline
This feature is supported only for JUnit 4.x (Not TestNG)
Since of 2.21.0 the provider surefire-junit47 can rerun scenarios created by cucumber-jvm 2.0.0 and higher.
Source : https://maven.apache.org/surefire/maven-surefire-plugin/examples/rerun-failing-tests.html

adding classpath using appassembler-maven-plugin for generating batch file

I am using appassembler from mojo. What I need to do is I have to add a perticular path of the project (say %BASEDIR%\resources) to class path, currently it is adding only %REPO% to the classpath. What changes should I do in my pom.xml. I have already provided below code.
<configurationDirectory>/some/path</configurationDirectory>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
And the output batch file contains
set CLASSPATH=%BASEDIR%\\..\SOME\PATH;%REPO%\abc.jar
What I my final outcome should be...
set CLASSPATH=%BASEDIR%\\..\SOME\PATH;%REPO%\abc.jar;%BASEDIR%\resources
What changes should incorporate in my pom.xml for achieving above outcome?
This question is really useful im many cases such as allowing different jdbc drivers or user plugins. In my case I wanted to have a jrebel build and therefore I had to change the classpath and switch the jar by the build directory. But I think it is not very difficult to modify the script to fit your needs. Note that you need maven >= 3.0.3 because since maven 3.0.3 all your plugins are executed in the very same order as they are in your pom.xml. So put this plugin right after your appassembler plugin call.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-beanshell</id>
<phase>package</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<evaluateBeanshell>
<condition>
import java.io.File;
import java.nio.file.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
print("replace jrebel classpath in ${basedir}/dist/bin/rebelServer");
Path path = Paths.get("${basedir}/dist/bin/rebelServer", new String[]{});
Charset charset = StandardCharsets.UTF_8;
String content = new String(Files.readAllBytes(path), charset);
content = content.replaceAll(
"\"\\$REPO\"/kic/engine/CoreEngine/[^/]+/CoreEngine\\-[^;:/]+\\.jar",
"${basedir}/build/classes");
Files.write(
path,
content.getBytes(charset),
new OpenOption[]{StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE}
);
true;
</condition>
</evaluateBeanshell>
</rules>
<fail>false</fail>
</configuration>
</execution>
</executions>
</plugin>

Maven goal to generate test report using damage control

I'm using Spock to test a Java application. I would like to generate test reports, in html, using damage-control
What maven goal shoud be executed to generate the reports?
It generated the reports running:
mvn com.github.damage-control.report:damage-control-maven-plugin:report
You should use goal provided by plugin.
Maven provides only phase's, not goals
So you should use phase test and goal report.
<execution>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
report goal is declared in this file DamageControlMojo.
/**
* #goal report
*/

Eclipse Maven multi module project with xmlbeans

I have a multi module project, in which one of the module ( say MODULE-A) generates sources and classes using xmlbeans plugin. So everytime when I do a clean install of parent project, eclipse recognizes all of the generated sources as new classes, and I don't want to commit the same files again and again when there is no schema change. To overcome this problem, I wrapped xmlbeans build under a profile so that I can build it with profile whenever there is a schema change. But it didn't solve the problem completely.
Whenever I try to do clean build of parent, MODULE-A is not creating 'schemaorg_apache_xmlbeans' under build directory ( which is something only generated by xmlbean plugin when I run with profile ). I can tell maven to exclude 'schemaorg_apache_xmlbeans' from the clean task. But I want to know if this is the right way to handle.
Appreciate your responses.
Thanks in advance
One alternative to this approach is to add this plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
This will allow the generated-sources to be added as a source folder so every time it generates you will have them built and available. You wouldn't commit these but when the actual jar gets built/released they will be in there and work all the same. This allows you to always be using code most up to date with your schema. This may not be the best solution for you but I found it to be a good idea when I ran into a similar situation.

Resources