Gradle没有运行测试

时间:2015-04-25 17:57:45

标签: java junit gradle

由于某些原因,gradle没有运行我的测试。当我执行gradle cleanTest test -i时,我得到:

Skipping task ':compileJava' as it is up-to-date (took 0.262 secs).
:compileJava UP-TO-DATE
:compileJava (Thread[main,5,main]) completed. Took 0.266 secs.
:processResources (Thread[main,5,main]) started.
:processResources
Skipping task ':processResources' as it has no source files.
:processResources UP-TO-DATE
:processResources (Thread[main,5,main]) completed. Took 0.001 secs.
:classes (Thread[main,5,main]) started.
:classes
Skipping task ':classes' as it has no actions.
:classes UP-TO-DATE
:classes (Thread[main,5,main]) completed. Took 0.0 secs.
:compileTestJava (Thread[main,5,main]) started.
:compileTestJava
Skipping task ':compileTestJava' as it has no source files.
:compileTestJava UP-TO-DATE
:compileTestJava (Thread[main,5,main]) completed. Took 0.001 secs.
:processTestResources (Thread[main,5,main]) started.
:processTestResources
Skipping task ':processTestResources' as it is up-to-date (took 0.004 secs).
:processTestResources UP-TO-DATE
:processTestResources (Thread[main,5,main]) completed. Took 0.007 secs.
:testClasses (Thread[main,5,main]) started.
:testClasses
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
file or directory '/Users/jan/2014-2015-groep-05/VoPro/build/classes/test', not found
Skipping task ':test' as it has no source files.

我的测试位于./test/文件夹中。这是我的gradle配置:

apply plugin: 'java'
apply plugin: 'eclipse'

test {
  testLogging {
    events "passed", "skipped", "failed", "standardOut", "standardError"
  }
  dependsOn 'cleanTest'
}

repositories {
  mavenCentral()
}

dependencies {
  testCompile("junit:junit")
}

sourceSets {
  main {
    java {
      srcDir 'src'
      srcDir 'test'
    }
  }
}

我似乎无法找到问题所在。 Gradle无法识别任何测试,因为test和cleanTest都是最新的,但是我确实将test /添加到了我的sourceSets。

2 个答案:

答案 0 :(得分:7)

您说 SourceSet应包含测试目录。该目录应在测试 SourceSet。

中设置

答案 1 :(得分:1)

用以下简单代码段替换sourceSet:

sourceSets.main.java.srcDirs = ['src']
sourceSets.test.java.srcDirs = ['tst']