Surefire system property not being set - maven

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.

Related

run main java from Intellij but should ready system properties set in pom.xml

How do i run normal main java but the system properties should be set through profile in pom.xml
i can get this work if i run junit test but not main java
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
[...]
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
I believe this is due to fact the systemPropertiesVariables set for maven-surefire-plugin.
You cannot set system Properties for running a Java program through Maven.
Maven only sets properties for the build (and the tests). Invoking the program after build is a completely different thing.

I'm getting an error from Maven saying "There are test failures", but I didn't write any test failures

This is the following error:
And these are the failed reports:
I'm completely new to maven so I'm not sure what any of this means
To clarify, maven is saying that it failed to execute it's goal (which was verify in this case). If you aren't running any test suites, maven will always record a failure, because it is configured to fail a build when you don't have any tests to run.
There are configurations which will allow maven to build successfully with no tests that can be set in your pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<failIfNoTests>false</failIfNoTests>
</configuration>
</plugin>
With this adjustment, maven will still build when you don't specify any tests. You never specified in your original post what your tests (if you have any) look like, so it's impossible to see if this is what the error is, or something else.
You need to find a way to ignore the test cases. Adding the following maven plugin solves the issue.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>

Passing threadCount to surefire plugin from maven cmdline

I have in my pom the following settings for maven surefire plugin.
Occasionally I might want to run the tests with less threads. I was hoping for a way to set it from the mvn command line.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
<configuration>
<parallel>methods</parallel>
<threadCount>5</threadCount>
<includes>
<include>com.Online.runner.Regression.ONLINE_Chrome_RunnerTest</include>
</includes>
</configuration>
</plugin>
When I attempt to use the command below it doesn't appear to work.
mvn clean test -X -DthreadCount=1
Checking the values through the debugger shows that has set a system property. But it seems to get ignored.
[DEBUG] Setting system property [threadCount]=[1]
[DEBUG] parallel='methods', perCoreThreadCount=true, threadCount=5,
My tests still run in parallel. What am I doing wrong? there must be a way to override this value in the Pom?
EDIT: It seems as though it is completely ignoring the threadCount value altogether even the one set in the POM. Is this value not passed to the dependency Junit47?
In order for it to work, remove it with pom.xml:
<threadCount> 5 </threadCount>
Maven startup line:
mvn test -DthreadCount=5

Insert MAVEN_OPTS in the POM.xml

I must increase java heap space to compile my project. The only way I found is modify mvn.bat and set:
set MAVEN_OPTS=-XX:PermSize=256m -XX:MaxPermSize=256m -Xms1300M -Xmx1300M
than all colleagues must change the file localy.
I want keep all inside my project, not localy. Can I insert in the POM.xml or other file?
Setting MAVEN_OPTS usually provides arguments to the JVM running the build, and these are passed down to the compiler because it runs inline. You have probably already noted that the maven-surefire-plugin used for test usually fork a separate process so passing options to the plugin is bound inside the pom.xml.
What if you fork the compilation process also and add the flags there, such as the below example.
Notice the fork and the compiler args
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
<compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>

Make maven's surefire show stacktrace in console

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>
..

Resources