【问题标题】:No line-after-line output from @Test block when running JUnit test with maven使用 maven 运行 JUnit 测试时,@Test 块没有逐行输出
【发布时间】:2012-02-27 21:23:06
【问题描述】:

我有一个在 maven 下运行的 Junit 测试 mvn clean test -Dtest=MyTest

输出如下:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building autotest-tests
[INFO]    task-segment: [clean, test]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory workspace/tests/target
[INFO] [compiler:testCompile {execution: compile tests}]
[INFO] Compiling 76 source files to workspace/tests/target/test-classes
[INFO] [surefire:test {execution: run tests}]
[INFO] Surefire report directory: workspace/tests/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Concurrency config is parallel='classes', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Output of @Before block...
Output of @Before block...
Output of @Before block...

然后输出停止。从@Test 块到命令行的任何逐行输出都会被阻止,我只有在测试结束后才能在控制台上看到它们:

Output of @Test block...
Output of @Test block...
Output of @Test block...

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 75.564 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 18 seconds
[INFO] Finished at: Mon Feb 06 12:22:22 CET 2012
[INFO] Final Memory: 24M/302M
[INFO] ------------------------------------------------------------------------

我以前做过工作,即在测试进行时,我在控制台上获得了逐行的测试输出。由于一段时间(也许是更新)停止了。

任何想法背后的原因是什么?

【问题讨论】:

    标签: maven junit maven-2 maven-surefire-plugin


    【解决方案1】:

    surefire 插件默认将输出写入文件。这可以通过useFile option 进行控制,可以从命令行设置:

    -Dsurefire.useFile=false
    

    也可以通过创建和激活配置文件将其设置为 settings.xml 中的默认值:

    <profiles>
        <profile>
            <id>sureFire.useFile</id>
            <properties>
                <surefire.useFile>false</surefire.useFile>
            </properties>
        </profile>
    </profile>
    <activeProfiles>
        <activeProfile>sureFire.useFile</activeProfile>
    </activeProfiles>
    

    【讨论】:

    • 我已经在 pom.xml 的 maven-surefire-plugin 配置中设置了 &lt;useFile&gt;false&lt;/useFile&gt;。我猜是一样的。
    猜你喜欢
    • 2021-12-16
    • 2019-04-25
    • 2019-07-26
    • 1970-01-01
    • 2012-08-07
    • 2013-08-23
    • 2012-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多