spock

Spock: How to use test data with @Stepwise

我与影子孤独终老i 提交于 2019-12-25 04:21:04
问题 I used @Stepwise for automation. 8 test methods are running sequentially to complete the process. One of the methods take parameter and I want to pass different parameters to the method. But the problem is: The method takes first set of parameter, then parameters are processed AND instead of proceeding to the next method, the method takes next set of parameter. The source looks like: @Stepwise class AOSearchPageTest extends GebReportingSpec { def "first_method"() { } def "second_method"() {

Grails unit testing custom codec using Spock

天涯浪子 提交于 2019-12-25 02:52:12
问题 I'd like to create a Spock unit test to test a custom codec I created. Most of the examples I see to test custom codecs are extending GrailsUnitTestCase to do this. Can someone point me in the right direction on how to do this using Spock? 回答1: I ended up doing the following: @TestMixin(GrailsUnitTestMixin) class SecureCodecSpec extends Specification { def setup() { grailsApplication.config.acme.encryption.password = 'topsecret' mockCodec(SecureCodec) } @Unroll def "SecureCodec with string

Grails unit testing custom codec using Spock

可紊 提交于 2019-12-25 02:51:52
问题 I'd like to create a Spock unit test to test a custom codec I created. Most of the examples I see to test custom codecs are extending GrailsUnitTestCase to do this. Can someone point me in the right direction on how to do this using Spock? 回答1: I ended up doing the following: @TestMixin(GrailsUnitTestMixin) class SecureCodecSpec extends Specification { def setup() { grailsApplication.config.acme.encryption.password = 'topsecret' mockCodec(SecureCodec) } @Unroll def "SecureCodec with string

Populate domain objects from tabular data in groovy

混江龙づ霸主 提交于 2019-12-25 02:38:09
问题 Have been using Spock a fair bit, and really like the ability to use tables in tests for input/output scenarios. example from spock docs: class Math extends Specification { def "maximum of two numbers"(int a, int b, int c) { expect: Math.max(a, b) == c where: a | b | c 1 | 3 | 3 7 | 4 | 4 0 | 0 | 0 } } I work in the finance industry where we deal with a lot of trading "books". Would be great to represent those books in tabular form. So instead of using builders, e.g: builder.addQuote( 1000000

Why does Spock think my Data Provider has no data?

旧巷老猫 提交于 2019-12-24 18:43:16
问题 I just wrote my own data Provider, which should read a file in chunks and provides it to my spock specification. While debugging the next() method returns a proper batch and the hasNext() returns false if the reader can not read any more lines. But I get this exception: SpockExecutionException: Data provider has no data Here is my Provider and my feature class DumpProvider implements Iterable<ArrayList<String>> { private File fileHandle private BufferedReader fileReader private ArrayList

Spock mocking inputStream causes infinite loop

非 Y 不嫁゛ 提交于 2019-12-24 08:25:22
问题 I have a code: gridFSFile.inputStream?.bytes When I try to test it this way: given: def inputStream = Mock(InputStream) def gridFSDBFile = Mock(GridFSDBFile) List<Byte> byteList = "test data".bytes ... then: 1 * gridFSDBFile.getInputStream() >> inputStream 1 * inputStream.getBytes() >> byteList 0 * _ The problem is that inputStream.read(_) is called infinite number of times. When I remove the 0 * _ - the test hangs until garbage collector dies. Please advise how can I properly mock the

Spock: method not recognized as an invocation

假装没事ソ 提交于 2019-12-24 08:13:25
问题 Trying to figure out why Spock doesn't seem to recognize a method call (of a Mocked object) as an invocation. Looked at the docs (http://spockframework.org/spock/docs/1.1-rc-3/all_in_one.html#_mocking) and couldn't figure it out. Here's a dumbed down version of the code: class VmExportTaskSplitter implements TaskSplitter<Export> { @Inject AssetServiceClient assetServiceClient @Override int splitAndSend(Export export) { Map batch = [:] Map tags = [:] if (true) { println('test') batch =

Unit testing DefaultHttpRequestRetryHandler

拥有回忆 提交于 2019-12-24 06:03:36
问题 I'm working on some legacy code that stores files to a remote server. I'd like to use Apache's DefaultHttpRequestRetryHandler to implement a retry logic. A simplified version of the implementation is shown below. How do I test my retry logic? I was able to manually test it by overriding retryRequest() in the DefaultHttpRequestRetryHandler class but an automated way would be nice. (I'm using Spock to test.) private CloseableHttpClient getHttpClient() { DefaultHttpRequestRetryHandler

get current user in grails spock unit testing which uses spring security

旧城冷巷雨未停 提交于 2019-12-24 05:57:50
问题 package com.rohan import grails.test.mixin.* import spock.lang.Specification import grails.plugins.springsecurity.SpringSecurityService import grails.test.mixin.domain.DomainClassUnitTestMixin import com.rohan.meta.MetaServiceCategory @TestFor(ProjectDashBoardController) @Mock([SpringSecurityService,User,Project,MetaServiceCategory,ProjectIntroduction,ProjectDetails,ProjectAdditionalInfo,SPCompany,BuyerCompany,Conversation,ServiceCategory,UserAuthService,TimeSheetService,ProjectService])

Spock @Unroll annotation

放肆的年华 提交于 2019-12-24 03:50:42
问题 During a recent code review, the question came up regarding whether the @Unroll annotation belongs at the class level or the method level. The class in question requires @Unroll on most of its methods but not all of them. Does declaring @Unroll incur any performance penalties if declared at the class level and not all methods of the class require it? 回答1: The @Unroll annotation is intended to be used on the method level. But it can also be used on the class level as indicated in the Unroll