加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 05:03:40 所属栏目:Java 来源:网络整理
导读:GNU Emacs 24.3.1Gradle 1.12spock-core.0.7 你好, 我正在使用gradle构建系统使用spock框架进行单元测试. 当我运行我的测试gradle测试时,我只看到这样的消息: * What went wrong:Execution failed for task ':test'. There were failing tests. See the rep
GNU Emacs 24.3.1
Gradle 1.12
spock-core.0.7

你好,

我正在使用gradle构建系统使用spock框架进行单元测试.

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

* 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

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

我的spock单元测试:

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

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

提前谢谢了,

解决方法

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

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

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

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

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

有关更多详细信息,请查看Gradle Build Language Reference中的测试.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读