使用spock junit测试和gradle构建系统在控制台上输出单元测试结果 [英] Output unit testing results on console using spock junit testing and gradle build system

查看:725
本文介绍了使用spock junit测试和gradle构建系统在控制台上输出单元测试结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  GNU Emacs 24.3.1 
Gradle 1.12
spock-core.0.7

你好,



我使用 spock framework 进行单元测试 gradle build 系统。



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

  *出错了:
执行失败,执行任务':'测试'。
>有失败的测试。请参阅以下文件:file:///home/projs/gradleTest/build/reports/tests/index.html

然后我必须去检查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());

我的Gradle构建文件:

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

repositories {
mavenLocal()
mavenCentral()
}
依赖关系{
compilecom.googlecode.json-simple:json-simple:1.1.1
testCompileorg.codehaus.groovy:groovy:2.3.3
testCompileorg.spockframework:spock-core:0.7-groovy-2.0



我的spock单元测试:

  import spock。 lang.Specification; 
class SnapClientTest extends Specification {
defWeb服务请求(){
给出:
SnapClient snapclient = new SnapClient()

expect:
snapclient.makeRequest()== 0
}
}

非常感谢,提前,

解决方案


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

默认情况下,您还会看到(输出中的更深层):




  • 哪些测试方法失败
  • 异常类型

  • 发生异常的源文件和行号


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

pre $ tasks.withType(Test){
testLogging {
exceptionFormatfull


code $


有关更多详细信息,请查看 Test Gradle Build Language Reference 中。


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


通常您会检查HTML报告,而不是XML文件。在Mac上,只需按住CMD并双击后的文件URL即可打开报告。请参阅报告。一些* nix终端提供了类似的功能。


GNU Emacs 24.3.1
Gradle 1.12
spock-core.0.7

Hello,

I am doing unit testing with spock framework using the gradle build system.

When I run my tests gradle test I just see a message like this:

* 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

Then I have to go and check the xml file to see what exception has been thrown

Is there any option where I could see the exceptions in my console output? For example I have some print message I would like printed to the console output:

    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());
    }

My Gradle build file:

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"
}

My spock unit test:

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

        expect:
        snapclient.makeRequest() == 0
    }
}

Many thanks in advance,

解决方案

When I run my tests gradle test I just see a message like this: [...]

By default, you'll also see (further up in the output):

  • Which test method(s) failed
  • The exception type
  • The source file and line number where the exception occurred

To see more information, configure Test#testLogging. For example:

tasks.withType(Test) {
    testLogging {
        exceptionFormat "full"
    }
}

For further details, check Test in the Gradle Build Language Reference.

Then I have to go and check the xml file to see what exception has been thrown

Typically you would check the HTML report, not the XML file. On Mac you can open the report simply by holding down CMD and double-clicking the file URL after See the report at:. Some *nix terminals offer a similar feature.

这篇关于使用spock junit测试和gradle构建系统在控制台上输出单元测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆