【问题标题】:How do I set test.testLogging.showStandardStreams to true from the command line?如何从命令行将 test.testLogging.showStandardStreams 设置为 true?
【发布时间】:2014-01-29 21:05:26
【问题描述】:

通过查看stdout上的日志,在编写单元测试时可以方便地调试一些外部库甚至内部代码。

虽然我可以将test.testLogging.showStandardStreams = true 添加到 build.graddle 文件中,但我宁愿做一些不那么永久的事情,例如从 gradle 的命令行执行中设置此标志。

我尝试了几种方法,似乎都没有:

gradle test -Dtest.testLogging.showStandardStreams=true
gradle test -Ptest.testLogging.showStandardStreams=true

以及通过更改属性字符串来更改这些选项。似乎没有任何作用。

如何从命令行设置test.testLogging.showStandardStreams=true

【问题讨论】:

    标签: gradle


    【解决方案1】:

    只使用环境变量:

    test {
        testLogging.showStandardStreams = (System.getenv('PRINTF_DEBUG') != null)
    }
    

    现在像这样运行你的测试用例:

    PRINTF_DEBUG=1 ./gradlew test --tests=com.yourspace.yourtest
    

    这将运行启用控制台输出并且只运行一个测试用例。由于产生的噪音,您通常不想为整个测试套件启用控制台输出。

    【讨论】:

      【解决方案2】:

      你可以像这样覆盖它

      gradle -Doverride.test.testLogging.info.showStandardStreams=true test
      

      或者您可以在项目中或~/.gradle/gradle.properties 中将其添加到您的gradle.properties

      systemProp.override.test.testLogging.info.showStandardStreams=true
      

      【讨论】:

        【解决方案3】:

        没有从命令行设置构建模型属性的内置方法。您必须让构建脚本查询分别通过-D-P 传入的系统或项目属性。

        【讨论】:

        • 添加答案时可能是这样,但现在可能。请参阅下面的答案
        猜你喜欢
        • 2021-09-12
        • 1970-01-01
        • 2013-05-15
        • 2010-09-08
        • 1970-01-01
        • 2011-02-28
        • 2020-02-26
        • 1970-01-01
        • 2015-05-25
        相关资源
        最近更新 更多