查看 gradle 的 junit 测试结果?

Q L*_*Liu 6 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.+'
}  
Run Code Online (Sandbox Code Playgroud)

当我在命令行中输入“gradle test”时,它会成功构建。

但是我在运行 gradle test 时出现以下错误:

按需创建属性(又名动态属性)已被弃用。

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

你可以在这里查看我的存储库:https : //github.com/quinnliu/WalnutiQ

kuk*_*ido 6

娇艳欲滴,

我不得不在你的 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.+'
}
Run Code Online (Sandbox Code Playgroud)

现在,结果$ 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
Run Code Online (Sandbox Code Playgroud)

我想你可以从这里拿走它: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
Run Code Online (Sandbox Code Playgroud)