News
A lot of training this fall
Yours truly is teaching several mini courses this fall:
- 📅Nov 2 . TESTING JVM APPLICATIONS WITH SPOCK
- 📅Nov 9 . ACCEPTANCE TESTS WITH GEB
- 📅Nov 16 . GRAILS TESTING DEEP DIVE
Moreover, @Schlogen, main Graeme Rocher's lieutenant in Grails and Micronaut development, is teaching the first Micronaut online training
- 📅 Nov 26 - Nov 28. MICRONAUT DEEP DIVE
Spock
Don't use .each in a then block!!!
When I started with Groovy, I fell into this trap. I think the issue is when you start with Groovy you don't understand that .each
, .findAll
, find
are using closures and it seems like a funny braces syntax.
I think any one teaching Groovy should explain that given:
class Book {
void printAuthorName(String name, Closure nameAction) {
println nameAction(name)
}
}
this code
Closure cls = {
it.toUpperCase()
}
new Book().printAuthorName('Sergio', cls)
is equivalent to:
new Book().printAuthorName('Sergio') {
it.toUpperCase()
}
Closure being the last argument of a method syntax is a foreign concept for many people. It was for me.
Undo MetaClass Changes
Spock has the extension ConfineMetaClassChanges that can be used to encapsulate meta class changes to a feature method or specification. Spock replaces the original meta class with a new one before a feature method is executed. After execution of a feature method the original meta class is used again.
Grails Test Pollution
In Part 1, @sbglasius finds Spock's @ConfineMetaClassChanges
not enough for his use case and creates a trait to help with metaClass
mocking.
It gets really interesting in Part 2.
The problem is, that when replacing anotherService with a Stub (or Mock or Spy), testService keeps this change in subsequent test cases
By default Grails services and controllers are singletons. Thus, the same bean will be used by every integration test. Thus, if you do a replacement it will leak to the rest of the integration tests.
He creates another handy trait, the MockServiceHelper
.
Micronaut
Micronaut 1.0 RC2 and the power of ahead-of-time compilation
https://twitter.com/graemerocher's sneak peek into the power of Micronaut's ahead of time compilation. See how to fight some Java framework development challenges:
- Type Erasure
- Missing Annotation Metadata
- No Parameter Names
Grails
Using Random Values For Configuration Properties
@mrhaki teaches another SpringBoot feature at our disposal in Grails 3 which I was not aware of.
Since Grails 3 we can use a random value for a configuration property. This is because Grails now uses Spring Boot and this adds the RandomValuePropertySource class to our application. We can use it to produce random string, integer or lang values.
@ConfigurationProperties in a Grails Application
Grails 3 apps are Spring Boot apps. Learn how property values can be bound to structured objects through @ConfigurationProperties.
Comment
Groovy 2.5.3 has been released, Spock 1.2 is out. Micronaut 1.0.0.RC2 has been out for a week and RC3 is around the corner. Autumn is heating up with releases.
In this issue, I link to several Spock/Grails topics. Enjoy!
Sergio del Amo