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?
Assuming you are using Grails 2.0, you should
@TestMixininstead of@Mixin.If you look at the source for the
TestFor, you will see this comment: