It is easy to use the Spock Framework, shipped with Grails, to mock or stub a collaborator (such as a service) in our Grails unit tests.
The Testing chapter explains a bit about mocking collaborators,
doWithConfig callback methods, the
FreshRuntime annotation to mock beans in tests — but they’re mainly for unit testing.
How about mocking beans in an integration test?
Continue reading “Grails 3.3 Integration Testing with Spock Mocks”
You’ll be glad to know that milestone 1 of Grails 3.3 has been released 3 days ago — and is also already available through SDKMAN!.
Not only has it upgraded its dependencies to Hibernate 5.1.5, Spring Framework 4.3.7, Spring Boot 1.5.3 and Gradle 3.5, but it also finally ships with the latest Spock 1.1 testing framework.
Continue reading “Grails 3.3 has Spock 1.1”
Since Groovy 1.0 we have groupBy and collectEntries to group elements from a Collection together into a Map. I had a little fun with them last week.
Continue reading “Groovy: Grouping using groupBy vs collectEntries”
Grails makes it very easy to put any logic of your application in a service. Just
grails create-service and you’re good to go. There’s a single instance by default, injectable anywhere. Powerful stuff and makes it easy to get up ‘n running very fast!
Creating a new application, following so-called “best practices” from blogs like these 🙂 and the ‘idiomatic Grails-way’ described in the docs and in tutorials work in the beginning, but there’s always a tipping point — where the application has grown a reasonable size — where one should start following a different, maybe less-Grailsey, strategy.
So what can go wrong by creating services in your application?
Continue reading “Grails Anti-Pattern: Everything is a Service”