spock

Can I override RESTClient default “HttpResponseException” response to >399 Return Codes?

廉价感情. 提交于 2019-12-03 10:53:44
I'm using the Groovy RESTClient class to do write some (spock) Acceptance tests for Java WebServices I've been authoring. One frustration I've had is in testing the responses... 200 Status's are easy: when: def result = callServiceWithValidParams() then: result.status == 200 But with 400+ I'm forced to either wrap in a try-catch , or test for the HttpResponseException that RESTClient throws by default. when: callWithInvalidParams() then: def e = thrown(Exception) e.message == 'Bad Request' This is sort-of OK, if a little frustrating... but I want to do better. Ideally, I want my tests to more

Mock final class in Spock

旧街凉风 提交于 2019-12-03 06:58:28
Can spock mock final classes? If so, how? Search results brought up this gist , which would seem to imply so, but I can't find any examples of doing so. I've also found forum posts that say mocking final classes isn't supported. Opal This specification: @Grab('org.spockframework:spock-core:1.0-groovy-2.4') @Grab('cglib:cglib-nodep:3.1') import spock.lang.* class Test extends Specification { def 'lol'() { given: def s = Mock(String) { size() >> 10 } expect: s.size() == 10 } } ends with the following exception: JUnit 4 Runner, Tests: 1, Failures: 1, Time: 29 Test Failure: lol(Test) org

Is there any way to do mock argument capturing in Spock

こ雲淡風輕ζ 提交于 2019-12-03 04:20:42
I have looked around and tried different things to no avail. The examples out there on the interwebs are few, and IMHO pretty simple. My use case: (the 'itocNetworkHandler' below is the mock) when: "we're doing stuff" StandardResponse response = cms.doCardStuff("123", "111", order) .... then: "we get proper calls and response object" 1 * cms.itocNetworkHandler.doNetworkCall( { it instanceof ReplacementRequestRecord }, StandardResponseRecord.class) >> record I would like to store away the parameter ('it') to the "doNetworkCall" on the mock. The reason i want the parameter is because the object

Using PowerMock with Spock

丶灬走出姿态 提交于 2019-12-03 03:46:01
I have a class with a few static methods.I need to Mock these static methods. I know PowerMock does this,but I was not able to find any tutorials/materials that shed some light on "Spock+PowerMock" integration. I prefer Spock to Junit,hence the conundrum. Is there a way of getting these 2 frameworks to play ball?Any help is much appreciated.Sample code,even more so. Update: Current Status of the Approach Spock behaving weirdly juanpaolo I was stuck here for a while too. After searching for hours, I saw this github repo: https://github.com/kriegaex/Spock_PowerMock . I tried adding a

七牛云宫静:基于容器和大数据平台的持续交付平台

匿名 (未验证) 提交于 2019-12-03 00:41:02
7 月 6 日上午,在 ArchSummit 2018 深圳站 | 全球架构师峰会上,七牛云工程效率部技术专家宫静分享了《基于容器和大数据平台的持续交付平台》为题的演讲。本文是对演讲内容的整理。? ? 本次分享的主要内容是基于 容器 和 大数据平台 去构建的持续交付系统,是七牛云工程效率部在持续交付、容器化方面去做的技术实践。将从以下两个方向展开:一个是容器化方向,一个是持续交付的平台。主要会结合在七牛云的实践来介绍这个持续集成、持续部署在容器化方向的探索和思考,以及未来方向的考虑。? 七牛云业务场景: 上图的数字其实是七牛云的业务场景的缩影,七牛云现在有六大产品线,围绕这六大核心业务,我们有 500 多个组件和服务,这个数字可能还在持续地变化,不断地上升,不断地发展。我们外部的业务需求是这样的,因为市场在快速变化,它对我们业务需求要求是有一个快速迭代的能力,快速发布的能力。工程效率部的目标是在保证质量的前提下来做到一个快速的验证和有效的发布的能力。而产品研发人员和工程效率这边是这样的一个人员比,在这样的一个人员比下,我们会遇到哪些问题呢? 以下是我们研发团队面临的一个真实的问题的总结。当一个团队中的开发人员面对的是怎么样一个开发场景,开发人员要面对的是多样化的编译运行环境,要保证从代码开发到编译到运行到调试自测这样一个完整的路径覆盖,当他完成这个路径过长的时候

Executing Specific Geb Tests according to environment

牧云@^-^@ 提交于 2019-12-03 00:39:28
I have a set of Spec tests I am executing within a Grails Project. I need to execute a certain set of Specs when I am on local, and another set of Spec when I run the pre-prod environment. My current config is executing all my specs at the same time for both environements, which is something I want to avoid. I have multiple environments, that I have configured in my GebConfig: environments { local { baseUrl = "http://localhost:8090/myApp/login/auth" } pre-prod { baseUrl = "https://preprod/myApp/login/auth" } } erdi You could use a spock config file. Create annotations for the two types of

BDD Java Testing with Spock

匿名 (未验证) 提交于 2019-12-02 20:59:24
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/itsoftchenfei/article/details/84984053 为何会专门写这篇BDD呢?之前我发表过一篇《 代码重构之TDD的思考 》,有童靴联系到我,探讨之余,感觉这几年集成化方面的测试方案产出太少了,优秀的也太少了。今天带大家了解一个新东西“BDD”,纠结是新瓶换旧药还是别的呢? BDD(Behavior-Driven Development),也叫行为驱动开发,感觉是不是像TDD(Test-Driven Development)一样的空白无力。其实不然,它是在TDD的基础上发展而来的一种软件开发方法。 首先我们剖析一下TDD的问题有哪些: 最大的弊端是面对一大堆的功能需求和用例时往往会感到无从下手 TDD更侧重于测试本身,因此容易忽视对业务需求的表达,最终沉溺于琐碎细节而无法自拔 它没有相应的系统的解决方案(相当一部分人认为junit/testng+Jmock就行) 那BDD就能解决上面这些问题吗?个人认为,不完全能够,它只是提供了一直新的思路,应该说是一整套的解决方案( spock )。 战略视角看 传统的软件开发(总而言之就是各司其职,浓厚的部门墙) BDD的本质在于尽可能避免在需求描述、用例撰写、代码实现、测试等各环节衔接、转译过程中发生的信息丢失

Spock test together with junit 5 test does not run

两盒软妹~` 提交于 2019-12-02 09:51:25
My stack: IDEA 2019.1.3 Springboot 2.1.6 Java 11 Maven 3.8.0 Groovy 2.5 Spock 1.3 Junit jupiter 5.5.1 Junit vintage 5.5.1 GMavenPlus Plugin 2.7.1 We would like to start writing tests in Spock testing framework. I followed this howto , but I was not successful. My spock tests are not running when I try to run all of my tests. I am able to run one test. I can "right-click" on test and run it. But if I try to run whole groovy package (or some package under Java package) it will not run those groovy tests. It will not run means following error: Jul 24, 2019 8:33:47 AM org.junit.platform.launcher

Spock test together with junit 5 test does not run

落花浮王杯 提交于 2019-12-02 07:27:12
问题 My stack: IDEA 2019.1.3 Springboot 2.1.6 Java 11 Maven 3.8.0 Groovy 2.5 Spock 1.3 Junit jupiter 5.5.1 Junit vintage 5.5.1 GMavenPlus Plugin 2.7.1 We would like to start writing tests in Spock testing framework. I followed this howto, but I was not successful. My spock tests are not running when I try to run all of my tests. I am able to run one test. I can "right-click" on test and run it. But if I try to run whole groovy package (or some package under Java package) it will not run those

Spock: mock a method with varargs

那年仲夏 提交于 2019-12-02 00:44:58
问题 This question is an offshoot of this Q&A: Test Groovy class that uses System.console() The problem: Spock framework incorrectly checks arguments of the mocked method with varargs. Steps to reproduce: 1) Create groovy project 2) Create an interface: interface IConsole { String readLine(String fmt, Object ... args) } 3) Create spock test: class TestInputMethods extends Specification { def 'test console input'() { setup: def consoleMock = GroovyMock(IConsole) 1 * consoleMock.readLine(_) >>