Spock - Repeat JSON Response

I use Grails 3.1.7 with inbuilt spock. It looks like I'm having troubles with stubbing a return value of service that is rendered by controller during the unit-tests execution. Service method returns null and then controller throws a GroovyRuntimeExc

Show better diff by saying 'containsAll' in Spock

I need to perform assertion that a collection contains all elements from the other collection. The following test should fail, because first collection doesn't contain 7 from the second one: def first = [6, 1, 5, 2, 4, 3] def second = [3, 4, 2, 5, 7,

Exception when using spock for Java unit tests

I am trying to use spock for testing my java based web application. Earlier we used to use, Junit along with Mockito for testing. I am trying to use @Collaborator and @Subject to autowire my dependencies like we used to use @Mock and @InjectMocks in

The object is not registered in the spock integration test

I have a Token entity: class Token { /** * Constants for various namespaces */ public static final String NS_PASSWORD_RESET = "pass-reset"; /** * A simple string unlimited in content that defines a scope of the token */ String namespace /** * Th

grailsApplication autowiring to spock tests are always null

Spock tests injects null to grailsApplication,as i tried autowiring both to grails service and to domain objects(spec) code(AttackSpec.groovy) package core import grails.test.mixin.TestFor import grails.test.mixin.TestMixin import grails.test.mixin.s

Java test class with many private methods

I have a class that has the responsibility of importing contracts from a CSV to database. The class itself has only one public method that starts the import and the other methods are all private (because only the class itself will use, and they hold

`shouldFail` against` throwed`

In investigating Groovy and Spock testing, I have run across two ways of catching exceptions: shouldFail and thrown. Is there a real difference between these two ways of asserting against exceptions? It looks like shouldFail is more JUnit-ish and thr

Using Groovy Trait in Grails Test Failure

How can I implement Groovy's new traits in my Grails Spock tests? Every time I try, I get a stacktrace that looks like this. Is there some limitation of Groovy trails that I might not be aware of? JDK Version: java version "1.7.0_65" OpenJDK Run

Grails Spock testing Controller and Service

Hi I have a controller called ApiController which uses a service called ApiService like so: def createCategory(){ def jsonObj = request.JSON jsonObj.each{ key, value -> params.put(key,value) } render apiService.createCategory(params) } Which works fi

Spock: How can I get the context of the failed test?

def "validate my files list"() { when: new File(folder).eachFileRecurse { validateFile(it) } then: notThrown(ValidationFailedException) where: folder << ['folder1', 'folder2'] } I have coded that simple test with Spock and Groovy. When it

Affirm two lists are equal under Spock

I test my application using Spock framework, the tests are written in Groovy. As a result of some method evaluation I have a list of objects. I want to test if this list is the same as the list I expect. I have coded the following: def expectedResult

Grails / Spock testing .. unexpected error thrown

Using spock to unit test a comand object .. I have a line in the command object .. some code .. } else { if ((val && obj.part) && obj.transactionType.transactionIsATransfer()) { println "obj.part .. class is ${obj.part.getClass()} ..

TestNG vs Spock for automation

We are looking at implementing a test framework and curious as to which framework to use. We are choosing between TestNG and Spock. This is going to be a UI Automation framework so it should handle as little mock data as possible. Our codebase will b

Grails 2.3 IntegrationSpec Can not Be Transactional

I upgrade to Grails 2.3 recently and try to migrate all old tests to spock integration test. But it fails at cleanup because my test is non-transactional. The Grails doc says test can be non-transactional, but we need to handle it manually, but it se

Why do not my unit tests work?

I have a fairly trivial Grails unit test: @TestFor(DateTimeTagLib) class DateTimeTagLibSpec extends Specification { def setup() { } def cleanup() { } void "showTime"() { assertEquals "14:26", new DateTimeTagLib().showTime(value: DateTi

How can I add more data to the assertion message?

Spock has great assertion support. But I've got one problem - I wanna add more context data (for example url of the checked page) to assertion info. I've tried assert a == b, [context] but in this case Spock doesn't print a and b valuesYou can either

Best practice of integrating Spock with Jenkins, Sonar

We decided to give Spock a try as a testing framework for our java based EE application. Currently we have a CI infrastructure deployed based on jenkins + maven + jacoco. Q: the question is what's the best way to integrated spock with all this? Any r

Spock without maven or step

I have a standard Java project that uses ant for building. I would like to add spock testing to this project without disrupting the current process. What is the minimum set of changes that would allow me to start to integrate spock testing into this