2016-09-28 180 views
0

我想创建一个新的gradle项目只是测试一些代码,但我不能运行测试用例。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 /测试/常规:

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 

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

回答

-1

尝试仅仅这在你的gradle产出:

依赖{
testCompile '的JUnit:JUnit的:4.12'}

+0

我已经试过了:'失败:生成失败并出现异常。 *出了什么问题: 无法推断Groovy类路径,因为在类路径中找不到Groovy Jar:文件集合 –

+0

试试这个如果有帮助:http://stackoverflow.com/questions/27955574/gradle-build-not -including-source-src-groovy –

+0

我想你的意思是这样的:'sourceSets.test.groovy.srcDirs = ['src']',但我不确定这是否正确并且不起作用 –

0

我拿到了 “问题” ......

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