【问题标题】:Viewing results of junit test for gradle?查看 gradle 的 junit 测试结果?
【发布时间】:2013-12-20 22:31:26
【问题描述】:

所以我目前有以下 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 test 时出现以下错误:

已弃用按需创建属性(也称为动态属性)。

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

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

【问题讨论】:

  • 如果构建成功,则测试通过。在build/reports/tests 中生成HTML 测试报告。为什么不使用与主源目录相同的方式定义测试源目录?

标签: junit gradle build.gradle


【解决方案1】:

清奇,

我不得不在你的 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】:

    当您运行gradle buildgradle test 时,会创建一个build 目录。 该目录是放置所有构建工件的地方。 在build 目录中是一个reports 目录。该目录是放置报告的地方。 比如pmd报告、junit报告等。

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-26
        • 2014-05-03
        • 1970-01-01
        • 1970-01-01
        • 2018-09-30
        • 1970-01-01
        相关资源
        最近更新 更多