Make maven's surefire show stacktrace in console - maven

I'd like to see the stacktrace of unit tests in the console. Does surefire support this?

A related problem that I found is that surefire in recent versions apparently sets trimStackTrace to true by default (rendering most stack trace in failed tests useless), which is quite inconvenient.
Setting -DtrimStackTrace=false or defining
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
solved this.

You can use the following command to see the stack trace on console instead of report files in the target/surefire-reports folder:
mvn -Dsurefire.useFile=false test

To extend the answer given before, you also can configure this behavior in your pom.xml:
..
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<useFile>false</useFile>
</configuration>
</plugin>
..

Related

Maven sure-fire-report name change not working

I am using Maven Sure fire plugin to generate report for my selenium TESTNG test suites.
After the test, it generates the output in the location ..\target\local\surefire-reports.
The name of the report is emailable-report.html.
I saw that we can chnage the name of the report by passing in Pom.xml.
Below in the section in pom.xml.
But I don't see the name changed after the report is generated. Am I missing something or are there any other way to change the name of 'emailable-report.html'
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<configuration>
<outputName>desired_name</outputName>
</configuration>
</plugin>
</plugins>
</reporting>
If you only use maven-surefire-report-plugin in your POM, then yes, the outputName parameter is ignored.
If you also add maven-site-plugin to your list of build plug-ins, then you will see the effect of using the outputName parameter.
So, for example:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M2</version>
<configuration>
<locales>en</locales>
</configuration>
</plugin>
</plugins>
</build>
...
<reporting>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<outputName>emailable-report</outputName>
</configuration>
</plugin>
</plugins>
</reporting>
When you do this, you will still continue to see a file called surefire-report.html being created - but now you will also see emailable-report.html as a separate file.
Both these files are in your project's /target/site/ directory.
They contain the same reporting statistics.
There is one difference between the 2 files: The emailable-report.html file is part of the Maven project web site - and therefore it contains navigation links similar to those shown in this official example.
Which links you see depends on how you have configured your Maven project web site.
In my case, it only shows links to the SureFire report and the JavaDocs.
But you may prefer to stick with the original surefire-report.html file, because of this, and just rename it to whatever you want.

comma separated parametrized maven ONLY tests one testng file

I am facing an issue with Maven which nowhere on internet I could find an answer for it. appreciate if anyone can help me with it. I aiming to test 2 testng files sent as parameter to POM as:
mvn clean test -DsuiteXmlFiles=1.xml,2.xml
and the POM file is:
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be usedfor compiling
the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
but, when i run, it ONLY runs the 2.xml file and runs it twice!!!
tried many options but no matter what is the second xml file it totally ignores the first and runs the second one twice.
can anyone please help?
thanks
Your surefire plugin should look like below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<skipTests>false</skipTests>
</configuration>
</plugin>
Pay close attention to <suiteXmlFiles>${file}</suiteXmlFiles>
So now you can pass in multiple suite files via
mvn clean test -Dfile=src/test/resources/suite-one-with-execution.xml, src/test/resources/suite-two-with-execution.xml
For more details you can refer to my blog post here.
finally understood where the issue was, for some reason i still dont know why, the Suite name in xml files should be not same as each other!!

Surefire system property not being set

I'm trying to get our Mule tests to run with verbose exceptions, but I cannot get the surefire plugin to set the appropriate system property correctly, here is my surefire config:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<mule.verbose.exceptions>true</mule.verbose.exceptions>
</systemPropertyVariables>
</configuration>
Now if I run maven with the command -Dmule.verbose.exceptions=true it prints verbose exceptions, but will not if I do a simple mvn test. Why are my system properties being ignored here?
I haven't checked the code but it could be caused by a static check that is performed previous to the surefire initialization. I would rather try the special variables mechanism described in the documentation.

Maven-release-plugin to skip compiling and running tests setup in pom.xml

Using maven-release-plugin, I have tried all possible ways I could (on command line as well), to skip compiling my tests but have not been successful so far. I want to do skip through pom. This is how my pom.xml looks
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<arguments>-Dmaven.test.skip</arguments>
<goals>deploy</goals>
</configuration>
</plugin>
I have tried solutions from this post:
How can I get maven-release-plugin to skip my tests? but couldn't get it to work.
Tried surefire http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#skip
but no luck.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
Please help to fix my pom.xml using maven-release-plugin preferably.
AFAIK this can only be done on the command line by setting
-Darguments="-Dmaven.test.skip=true -DskipTests"
First you need to figure out how to solve this without the maven-release-plugin. Compilation of the test-classes is done by the org.apache.maven.plugins:maven-compiler-plugin:testCompile, while the execution is done by org.apache.maven.plugins:maven-surefire-plugin:test.
So it is possible, but maybe the real question is: why do you want this? Isn't this a workaround for the real cause?

findbugs maven plugin site vs check

I'm just trying to wrap my head around a couple of things.
If I have this in my masterpom:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<failOnError>false</failOnError>
<threshold>High</threshold>
<effort>Default</effort>
<xmlOutput>true</xmlOutput>
<skip>${skipFindBugs}</skip>
<xmlOutputDirectory>target/reports/findbugs</xmlOutputDirectory>
<excludeFilterFile>
src/main/resources/findbugs-exclude-filters.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
My findbugs-exclude-filters.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Bug category="I18N" />
</Match>
</FindBugsFilter>
QUESTIONS
Why does clean verify site report 2 warnings, but clean verify findbugs:check return 14 bugs? I don't understand what the difference is.
Why does my site report warn about I18N:DM_DEFAULT_ENCODING
The findbugs-maven-plugin plugin needs to be configured in BOTH the <reporting><plugins/></reporting> and <build><plugins/></build> section. Have experimented with this all sorts of ways and the only way I have been able to get it to work is to duplicate findbugs-maven-plugin configuration.
So try adding something like the following in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<failOnError>false</failOnError>
<threshold>High</threshold>
<effort>Default</effort>
<xmlOutput>true</xmlOutput>
<skip>${skipFindBugs}</skip>
<xmlOutputDirectory>target/reports/findbugs</xmlOutputDirectory>
<excludeFilterFile>
src/main/resources/findbugs-exclude-filters.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</build>
Note that it's a cut and paste of what you posted inside of the <reporting/> block. I have not tested the above. I'm just trying to give you a general idea here.
The Reporting section of the POM Reference states that:
And the subtler difference is that a plugin configuration under the reporting element works as build plugin configuration, although the opposite is not true (a build plugin configuration does not affect a reporting plugin).
I have been able to make this work with Maven 3.0.5. I have not tried it on 3.1.0 yet.

Resources