查看junit test for gradle的结果?

时间:2013-12-20 22:31:26

标签: junit gradle build.gradle

所以我目前有以下build.gradle文件:

apply plugin: 'java'

sourceSets {
    main {
        java {
            srcDir 'src/model'
        }
    }

    test {
        srcDirs = ["tests/model"]
    }
}

dependencies {
    compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')
    runtime fileTree(dir: 'libs', include: '*.jar')

    testCompile group: 'junit', name: 'junit', version: '4.+'
}  
当我在命令行中输入“gradle test”时,

成功构建。

但是,在运行gradle测试时出现以下错误:

不推荐按需创建属性(a.k.a动态属性)。

正如您所看到的,我的junit测试都在文件夹test / model /中,但我想知道如何通过我的junit测试的结果?

您可以在此处查看我的存储库:https://github.com/quinnliu/WalnutiQ

3 个答案:

答案 0 :(得分:4)

当您运行gradle buildgradle test时,会创建一个build目录。 此目录是放置所有构建工件的位置。 build目录内是reports目录。此目录是放置报告的位置。 例如,pmd报告,junit报告等

JUnit报告位于tests目录中。在浏览器中打开index.html文件以查看报告。

答案 1 :(得分:4)

Chingy与,

我必须在build.gradle中更新一些内容:

测试的源集
添加了Maven存储库以获取JUnit库

apply plugin: 'java'

repositories {
    mavenCentral()
}

sourceSets {
    main {
        java {
            srcDir 'src/model'
        }
    }

    test {
        java {
            srcDir 'tests/model'
        }
    }
}

dependencies {
    compile files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')
    runtime fileTree(dir: 'libs', include: '*.jar')

    testCompile group: 'junit', name: 'junit', version: '4.+'
}

现在,$ gradle build的结果:

bender:WalnutiQ demo$ gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processTestResources UP-TO-DATE
:testClasses
:test

model.RetinaTest > test_seeBMPImage FAILED
    java.lang.IllegalArgumentException at RetinaTest.java:25

model.MARK_I.SpatialPoolerTest > test_performSpatialPoolingOnRegion FAILED
    java.lang.IllegalArgumentException at SpatialPoolerTest.java:60

model.util.JsonFileInputOutputTest > test_saveRegionObject FAILED
    java.lang.IllegalArgumentException at JsonFileInputOutputTest.java:69

model.util.SynapsePermanencesViewerTest > test_saveRegionToBeOpenedInSynapsePermanencesViewer FAILED
    java.lang.IllegalArgumentException at SynapsePermanencesViewerTest.java:45

49 tests completed, 4 failed
:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/demo/development/tmp/WalnutiQ/build/reports/tests/index.html

我想你可以从这里拿走它:o)

PS:我建议重构您的项目结构以匹配Maven / Gradle结构,这样您就不必处理源集,它将使您的build.gradle更清洁。

src/main/java   Production Java source
src/main/resources  Production resources
src/test/java   Test Java source
src/test/resources  Test resources
src/sourceSet/java  Java source for the given source set
src/sourceSet/resources Resources for the given source set

答案 2 :(得分:3)

您可以使用测试块中的以下命令指定JUnit测试结果的位置。

test {
    reports.junitXml.destination = file('build/test-results/folder')
}