Grails - What is a mixin and its implications for Grails testing?

I am learning Grails Testing and the first paragraph of the documentation says that

Grails 2.0.x and above deprecates these test harnesses in favor of mixins that can be applied to a variety of different tests (JUnit 3, JUnit 4, Spock, etc.) without subclassing

I researched about this, finding that it is used for special multiple inheritance in another language. I also found the following statement:

First, you should notice that mixins only exist in languages ​​with multiple inheritances. You cannot use mixin in Java or C #.

Can someone explain what a mixin is and what it means in Grails testing?

+3


source to share


1 answer


Can someone explain what a mixin is and what it means in Grails Testing?

Mixins contain behavior that can be "mixed" with other classes. Using inheritance in Groovy or Java, only one superclass can be inherited. Mixins allow you to inject behavior into a class from several other classes.



In earlier versions of Grails, your unit test classes would typically inherit from GroovyTestCase

or GrailsUnitTestCase

so that your test inherits useful behavior. The problem is that if you wanted to use Spock or some other testing framework that comes up in the future, it was tricky because you would like to inherit the behavior from the Spock test class, but also would like to inherit the behavior from the Grails test class With mixins, we let your unit tests "inherit" all of the Grails test behavior through the mixin, so we don't bind your option 1 inheritance and leave you to inherit from the Spocks test class if you wish.

There are many ways mixins make things better. This is just one.

+3


source







All Articles