与junit5隐藏堆栈跟踪的maven surefire

时间:2017-08-22 09:15:51

标签: java maven junit maven-surefire-plugin junit5

如果我这样做:

$

mvn -X \
     -Dtest=MojoIntegrationTest \
     -Dsurefire.trimStackTrace=false \
     -Dsurefire.useFile=false  \
     clean test

@BeforeEach public void setUp() { stuff(); } @Test public void testMyApp() { doApp(); } stuff()以某种方式爆炸,我无法在控制台和文件中获得完整的堆栈跟踪。 JUnit5或Maven都隐藏了它们:

doApp()

除此之外:

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

我真的不喜欢,我怎么能得到堆栈跟踪?

感谢。

[更新1] :来自我的pom的确定配置:

@BeforeEach
public void setUp() {
    try {
        stuff();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
 }

和JUnit5依赖项:

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

Maven surefire docs here

[更新2] :最初这只影响我的 <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> 例程,但现在我正在编写测试,我意识到它实际上到处都是,即mvn和junit5隐藏所有我的stacktraces。

1 个答案:

答案 0 :(得分:5)

您必须使用-DtrimStackTrace=false代替-Dsurefire.trimStackTrace=false

mvn clean test -DtrimStackTrace=false

有关详细信息,请参阅http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html