(Quick Reference) # 15.1 Unit Testing Version: 6.0.0 ## 15.1 Unit Testing Unit testing are tests at the "unit" level. In other words you are testing individual methods or blocks of code without consideration for surrounding infrastructure. Unit tests are typically run without the presence of physical resources that involve I/O such as databases, socket connections or files. This is to ensure they run as quick as possible since quick feedback is important. Since Grails 3.3, the Grails Testing Support Framework is used for all unit tests. This support provides a set of traits. An example hello world test can be seen below:
    import spock.lang.Specification
    import grails.testing.web.controllers.ControllerUnitTest

    class HelloControllerTests extends Specification implements ControllerUnitTest<HelloController> {

        void "Test message action"() {
            when:"The message action is invoked"
            controller.message()

            then:"Hello is returned"
            response.text == 'Hello'
        }
    }
For more information on writing tests with Grails Testing Support see the dedicated documentation. Versions of Grails below 3.2 used the Grails Test Mixin Framework which was based on the `@TestMixin` AST transformation. This library has been superceded by the simpler and more IDE friendly trait based implementation. | Quick Reference (hide)