If I do this:
mvn -X \
-Dtest=MojoIntegrationTest \
-Dsurefire.trimStackTrace=false \
-Dsurefire.useFile=false \
clean test
@BeforeEach
public void setUp() {
stuff();
}
@Test
public void testMyApp() {
doApp();
}
and stuff()
or doApp()
blows up somehow, I don't get the full stacktrace, neither in the console nor in the files. Either JUnit5 or Maven is hiding them:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.me.config.plugin.MojoIntegrationTest
Created C:\dev\workspace\gem-config-maven-plugin\target\test-classes\test-project\target
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 2.133 sec <<< FAILURE! - in com.me.config.plugin.MojoIntegrationTest
testFindCommonPropertiesFromDependency Time elapsed: 1.6 sec <<< FAILURE!
java.lang.NullPointerException
at com.me.config.plugin.MojoIntegrationTest.setUp(MojoIntegrationTest.java:168)
testRetrievalOfConfigJar Time elapsed: 0.283 sec <<< FAILURE!
java.lang.NullPointerException
at com.me.config.plugin.MojoIntegrationTest.setUp(MojoIntegrationTest.java:168)
testOutputPropertiesFilesForAllEnvironments Time elapsed: 0.2 sec <<< FAILURE!
java.lang.NullPointerException
at com.me.config.plugin.MojoIntegrationTest.setUp(MojoIntegrationTest.java:168)
Results :
Failed tests:
MojoIntegrationTest.setUp:168 » NullPointer
MojoIntegrationTest.setUp:168 » NullPointer
MojoIntegrationTest.setUp:168 » NullPointer
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.717 s
[INFO] Finished at: 2017-08-21T18:23:05+01:00
[INFO] Final Memory: 31M/389M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project gem-config-maven-plugin: There are test failures.
[ERROR]
[ERROR] Please refer to C:\dev\workspace\gem-config-maven-plugin\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project gem-config-maven-plugin: There are test failures.
Please refer to C:\dev\workspace\gem-config-maven-plugin\target\surefire-reports for the individual test results.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.
Apart from doing this:
@BeforeEach
public void setUp() {
try {
stuff();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
which I really don't like, how can I get the stacktrace?
Thanks.
[UPDATE 1]: the config for surefire from my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
<properties>
<excludeTags>integration</excludeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider
</artifactId>
<version>1.0.0-M5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
and the JUnit5 dependencies:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>4.12.0-M5</version>
<scope>test</scope>
</dependency>
[UPDATE 2]: originally this was just affecting my @BeforeEach
routine, but now that I am writing tests, I realise it is actually everywhere, i.e. mvn and junit5 is hiding all my stacktraces.
catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); throw e; }
- you can get the error message frome.getMessage()
. – Masqatsurefire.trimStackTrace
andsurefire.useFile
options? – Giblets