【问题标题】:gradle compiles but does not run tests [duplicate]gradle 编译但不运行测试 [重复]
【发布时间】:2017-02-06 03:44:43
【问题描述】:

我正在尝试创建一个新的 gradle 项目来测试一些代码,但我无法运行测试用例。

我的文件夹结构如下:

- src
    - main
        - groovy
        - java
        - resources
    - test
        - groovy
        - java
        - resources

我的 build.gradle:

group 'test'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

还有一个测试,在 src/test/groovy:

import groovy.util.logging.Log
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@Log
@RunWith(JUnit4.class)
class TestA {
    TestA() {
        println "hello"
    }

    @Test
    void "test"() {
        println "a"
        log.info("b")
    }
}

当我通过命令行运行 ./gradlew.bat test 时,我得到了这个:

{ test }  » ./gradlew.bat test
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:test

BUILD SUCCESSFUL

Total time: 5.333 secs

一切都应该是正确的,但没有打印出来,我不知道为什么。

【问题讨论】:

    标签: testing gradle groovy junit


    【解决方案1】:

    我遇到了“问题”……

    ./gradlew.bat test 没有打印输出。为此,有必要在末尾添加-i

    【讨论】:

      【解决方案2】:

      只在你的 gradle 中试试这个:

      依赖{
      testCompile 'junit:junit:4.12'}

      【讨论】:

      • 我也试过了:FAILURE: Build failed with an exception. * What went wrong: Cannot infer Groovy class path because no Groovy Jar was found on class path: file collection
      • 如果有帮助试试这个:stackoverflow.com/questions/27955574/…
      • 我猜你的意思是:sourceSets.test.groovy.srcDirs = [ 'src' ],但我不确定这是否正确并且它不起作用
      猜你喜欢
      • 1970-01-01
      • 2017-09-24
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多