GrailsUnitTestMixin (Grails 3.2.6)
Date: 2017-02-09

Package: grails.test.mixin.support

## [Groovy] Class GrailsUnitTestMixin

- grails.test.mixin.support.GrailsUnitTestMixin

- A base unit testing mixin that watches for MetaClass changes and unbinds them on tear down.

  Authors:
    Graeme Rocher
  Since:
    2.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `GrailsUnitTestMixin (java.util.Set<java.lang.String> features)`
    `GrailsUnitTestMixin ()`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `void` | `defineBeans(boolean immediateDelivery = true, groovy.lang.Closure<?> closure)`
    `org.springframework.context.ConfigurableApplicationContext` | `getApplicationContext()`
    `Config` | `getConfig()`
    `GrailsApplication` | `getGrailsApplication()`
    `org.springframework.context.ConfigurableApplicationContext` | `getMainContext()`
    `org.springframework.context.MessageSource` | `getMessageSource()`
    `void` | `mockCodec(java.lang.Class<?> codecClass)` Loads the given codec, adding the "encodeAs...()" and "decode...()" methods to objects.
    `java.lang.String` | `shouldFail(groovy.lang.Closure code)` Asserts that the given code closure fails when it is evaluated
    `java.lang.String` | `shouldFail(java.lang.Class<?> clazz, groovy.lang.Closure code)` Asserts that the given code closure fails when it is evaluated and that a particular exception is thrown.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class TestMixinRuntimeSupport` | `getFeatures, getRuntime, setRuntime, setTestClass`
    `class groovy.lang.GroovyObjectSupport` | `groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll()`

- - ### Constructor Detail

    - #### GrailsUnitTestMixin(java.util.Set<java.lang.String> features)

    - #### GrailsUnitTestMixin()

  - ### Method Detail

    - #### void defineBeans(boolean immediateDelivery = true, groovy.lang.Closure<?> closure)

    - #### org.springframework.context.ConfigurableApplicationContext getApplicationContext()

    - #### Config getConfig()

    - #### GrailsApplication getGrailsApplication()

    - #### org.springframework.context.ConfigurableApplicationContext getMainContext()

    - #### org.springframework.context.MessageSource getMessageSource()

    - #### void mockCodec(java.lang.Class<?> codecClass)

      Loads the given codec, adding the "encodeAs...()" and "decode...()" methods to objects.

      Parameters:
        `codecClass` - The codec to load, e.g. HTMLCodec.

    - #### java.lang.String shouldFail(groovy.lang.Closure code)

      Asserts that the given code closure fails when it is evaluated

      Parameters:
        code
      Returns:
        the message of the thrown Throwable

    - #### java.lang.String shouldFail(java.lang.Class<?> clazz, groovy.lang.Closure code)

      Asserts that the given code closure fails when it is evaluated and that a particular exception is thrown.

      Parameters:
        `clazz` - the class of the expected exception
        `code` - the closure that should fail
      Returns:
        the message of the expected Throwable