Gradle:如何列出所有“给定测试”

时间:2014-11-10 03:50:23

标签: java testing groovy junit gradle

我尝试以下代码:

roroco@roroco ~/Dropbox/jvs/ro-idea $ gradle test --tests "ro.idea.ToggleTest.testIsAd"
:ro:compileJava UP-TO-DATE
:ro:processResources UP-TO-DATE
:ro:classes UP-TO-DATE
:ro:jar
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
:ro:compileTestJava UP-TO-DATE
:ro:processTestResources UP-TO-DATE
:ro:testClasses UP-TO-DATE
:ro:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ro:test'.
> No tests found for given includes: [ro.idea.ToggleTest.testIsAd]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

输出显示"没有找到给定的测试包括",我的问题是:如何列出所有"给定测试"以及如何指定"给出测试"

this是我的老问题

2 个答案:

答案 0 :(得分:5)

我不确定在执行之前列出所有给定的测试,因为在测试实际执行之前我不相信这是已知的。

您可以将其添加到build.gradle文件中:

test {
  beforeTest { descriptor ->
     logger.lifecycle("Running test: ${descriptor}")
  }
}

然后,如果你去:

gradle clean test

它将运行所有测试,但也会在执行之前打印出测试描述符,提供method(className),如下所示:

:test
Running test: test testC(org.gradle.MySecondTest)
Running test: test testD(org.gradle.MySecondTest)
Running test: test testA(org.gradle.MyFirstTest)
Running test: test testB(org.gradle.MyFirstTest)

或者,您可以在不更改build.gradle文件的情况下运行上一个命令,并查看将显示所有测试运行的build/reports/tests/index.html文件。

那么您可以使用以下命令指定单个测试:

gradle clean test --tests "org.gradle.MyFirstTest.testA"

或者班级中的所有测试:

gradle clean test --tests "org.gradle.MyFirstTest"

或包中的所有测试:

gradle clean test --tests "org.gradle.*"

答案 1 :(得分:1)

您还可以使用:

test {
    testLogging {
        events "passed", "skipped", "failed"
    }
}