Gradle即使运行test.useTestNG()也不会运行TestNG测试

amo*_*fis 2 testng gradle

我的build.gradle样子是这样的:

apply plugin: 'scala'
apply plugin: 'java'

sourceCompatibility = 1.8
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.scala-lang:scala-library:2.11.4"

    compile 'org.reactivestreams:reactive-streams:1.0.0.RC1'
    compile 'org.reactivestreams:reactive-streams-tck:1.0.0.RC1'

    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile group: 'org.testng', name: 'testng', version: '5.14.10'
}

test {
    useTestNG()
}
Run Code Online (Sandbox Code Playgroud)

我在Scala中有一些实现,在Java中有TestNG测试。测试类实际上不包含任何测试,但是它的父类包含任何测试。Gradle似乎认为班上没有考试。

Skipping task ':testClasses' as it has no actions.
:testClasses UP-TO-DATE
:testClasses (Thread[main,5,main]) completed. Took 0.001 secs.
:test (Thread[main,5,main]) started.
:test
Skipping task ':test' as it is up-to-date (took 0.048 secs).
:test UP-TO-DATE
Run Code Online (Sandbox Code Playgroud)

测试类在 build/classes/test

Opa*_*pal 5

tl; dr

将以下代码添加到build.gradle

tasks.withType(Test) {
    scanForTestClasses = false
    include "**/*Test.class" // whatever Ant pattern matches your test class files
}
Run Code Online (Sandbox Code Playgroud)

说明:

是导致您遇到问题的错误。而这里的办法可以解决。别忘了对所有答案进行投票(我的意思是彼得的回答;)