当前位置: 首页 > 知识库问答 >
问题:

Maven使用JUnit 5隐藏stacktraces

程化
2023-03-14

如果我这样做:

mvn -X \
     -Dtest=MojoIntegrationTest \
     -Dsurefire.trimStackTrace=false \
     -Dsurefire.useFile=false  \
     clean test
@BeforeEach
public void setUp() {
    stuff();
}

@Test
public void testMyApp() {
    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.
@BeforeEach
public void setUp() {
    try {
        stuff();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
 }
        <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>
    <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>

[更新2]:最初这只是影响我的@beforeeach例程,但现在我正在编写测试,我意识到它实际上无处不在,即mvn和junit5隐藏了我所有的堆栈痕迹。

共有1个答案

郑星雨
2023-03-14

必须使用-dtrimstacktrace=false而不是-dsurefire.trimstacktrace=false:

mvn clean test -DtrimStackTrace=false

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

 类似资料:
  • 我有一个代码与许多评论,我如何可以隐藏这些,但没有删除,我需要他们之后。

  • 问题内容: 我的html中有这样的标签: 使用CSS我想用我的实际徽标替换文本。我已经通过调整标签大小并通过css将背景图像放到徽标中了,没有问题。但是,我不知道如何摆脱文本。我以前看过基本上是通过将文本从屏幕上推送来完成的。问题是我不记得在哪里看到它。 问题答案: 这是一种方法: 这是隐藏文本的另一种方式,同时避免了浏览器将创建的9999像素大框:

  • 我想在Eclipse(Oxygen 4.7.1a)中使用JUnit 5创建一个JUnit测试。这个JUnit测试应该在一个名为test的独立src文件夹中。但是,由于我是JUnit和Java9的新手,我遇到了以下问题。 我不想为此使用像Gradle或Maven这样构建工具。 因为我有两个不同的src文件夹,一个用于项目src,另一个用于测试用例: 我需要两个module-info.java文件吗?

  • 问题内容: Maven执行 我正在尝试使用我的一个Maven项目,但在此阶段无法使用- 我得到的输出是- 尝试实施上述解决方案@ Surefire没有采用Junit5测试来将依赖关系更新为- 并将插件更新为- 但输出保持不变。 问题 -这是自定义提供没有更多的支持,或者是有什么解决方案使用执行测试,和/或 现在? 注意 -测试执行在JUnit-4上运行良好。 问题答案: 您应该像这样配置maven

  • 我们想隐藏“有优惠券吗?添加一张…”在WooCommerce结账时,如果已添加优惠券或客户在结账页面上添加优惠券。 目前,我们在下面有此代码,当客户在购物车页面输入优惠券,然后导航到结帐页面时,此代码有效。在这种情况下,“拥有优惠券?添加一张…”消息不可见。如果购物车页面上未添加优惠券,则消息可见。 这很好用!但是,当客户在结账页面上添加优惠券时,它不起作用。 1.)我们收到消息“优惠券已添加”,

  • 我已经看到了Gradle的示例,其中API密钥存储在Gradle中。属性文件。然后修改构建。gradle文件,然后在Java应用程序中为其使用变量。 我如何在Maven项目中做类似的事情?