Grails 2.0 unit test using @TestFor and @Mixin
-
06-12-2019 - |
Question
I commonly use Mixins in test code to share utility methods across tests. I have a test that I wrote which has a @TestFor
and @Mixin
. The behavior that I'm seeing is that when I have the @TestFor
annotation the test does not see my @Mixin
code and gives me a MissingMethodException when executed. When I remove the @TestFor
it works fine. Below is a simplified example of what I'm trying to do.
@Mixin(TagLibTestUtils)
@TestFor(ErrorMessageTagLib)
class ErrorMessageTagLibTests {
@Test
void stuff() {
something()
}
}
class TagLibTestUtils {
def something() {
println ">>> HERE"
}
}
So my question is do @Mixin
and @TestFor
annotations not work together? Or am I doing something wrong here?
Solution
Assuming you are using Grails 2.0, you should @TestMixin
instead of @Mixin
.
If you look at the source for the TestFor
, you will see this comment:
/**
* Used to indicate the class under test. Triggers the @TestMixin AST transform for the given artefact type.
*
* @author Graeme Rocher
* @since 2.0
*/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow