java – 使用spock junit测试和gradle构建系统在控制台上输出单
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 } } 提前谢谢了, 解决方法
默认情况下,您还会看到(在输出中更进一步): >哪种测试方法失败了 要查看更多信息,请配置Test#testLogging.例如: tasks.withType(Test) { testLogging { exceptionFormat "full" } } 有关更多详细信息,请查看Gradle Build Language Reference中的测试.
通常,您将检查HTML报告,而不是XML文件.在Mac上,只需按住CMD并在查看报告位置后双击文件URL即可打开报告.一些* nix终端提供类似的功能. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |