使用spock junit测试和gradle构建系统在控制台上输出单元测试结果

ant*_*009 5 java gradle spock

GNU Emacs 24.3.1
Gradle 1.12
spock-core.0.7
Run Code Online (Sandbox Code Playgroud)

你好,

我正在spock framework使用该gradle build系统进行单元测试.

当我运行我的测试时,gradle test我只看到这样的消息:

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/projs/gradleTest/build/reports/tests/index.html
Run Code Online (Sandbox Code Playgroud)

然后我必须去检查xml文件以查看抛出了什么异常

有没有我可以在控制台输出中看到异常的选项?例如,我有一些打印消息,我想打印到控制台输出:

    catch(FileNotFoundException ex) {
        System.out.println("Exception " + ex.toString());
    }
    catch(IOException ex) {
        System.out.println("Exception " + ex.toString());
    }
    catch(Exception ex) {
        System.out.println("Exception " + ex.toString());
    }
Run Code Online (Sandbox Code Playgroud)

我的Gradle构建文件:

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'groovy'

repositories {
              mavenLocal()
              mavenCentral()
}
dependencies {
             compile "com.googlecode.json-simple:json-simple:1.1.1"
             testCompile "org.codehaus.groovy:groovy:2.3.3"
             testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
Run Code Online (Sandbox Code Playgroud)

我的spock单元测试:

import spock.lang.Specification;
class SnapClientTest extends Specification {
    def "Request from web services"() {
        given:
        SnapClient snapclient = new SnapClient()

        expect:
        snapclient.makeRequest() == 0
    }
}
Run Code Online (Sandbox Code Playgroud)

提前谢谢了,

Pet*_*ser 14

当我运行我的测试gradle测试时,我只看到这样的消息:[...]

默认情况下,您还会看到(在输出中更进一步):

  • 哪种测试方法失败了
  • 异常类型
  • 发生异常的源文件和行号

要查看更多信息,请进行配置Test#testLogging.例如:

tasks.withType(Test) {
    testLogging {
        exceptionFormat "full"
    }
}
Run Code Online (Sandbox Code Playgroud)

欲知详情,请Test摇篮构建语言参考.

然后我必须去检查xml文件以查看抛出了什么异常

通常,您将检查HTML报告,而不是XML文件.在Mac上,只需按住CMD并双击文件URL即可打开报告See the report at:.一些*nix终端提供类似的功能.