GrailsTestTypeSupport (Grails 2.4.4)
Date: 2014-10-28

Package: org.codehaus.groovy.grails.test.support

## [Groovy] Class GrailsTestTypeSupport

- org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport

- All Implemented Interfaces and Traits:
    GrailsTestType

      abstract class GrailsTestTypeSupport
      extends java.lang.Object

  Provides a convenient base for GrailsTestType implementations.

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `groovy.lang.Binding` | `buildBinding` The binding from the build environment
    `java.io.File` | `compiledClassesDir` The location where the type's source was compiled to
    `java.lang.String` | `name` The name of this test type
    `java.lang.String` | `relativeSourcePath` The path to this type's source, relative to the root of all test source
    `GrailsTestTargetPattern[]` | `testTargetPatterns` The test target patterns that should be used to filter the tests to run

  - ### Constructor Summary

    Constructors
    Constructor and description
    `GrailsTestTypeSupport (java.lang.String name, java.lang.String relativeSourcePath)` Sets the name and relativeSourcePath

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `void` | `cleanup()` Called after the tests have completed, regardless of success or not.
    `protected SystemOutAndErrSwapper` | `createSystemOutAndErrSwapper()` Creates swapper with echo parameters based on testOptions.echoOut and testOptions.echoErr in the build binding.
    `protected int` | `doPrepare()` Do any preparation and return the (approximate) number of tests that will be run.
    `protected GrailsTestTypeResult` | `doRun(GrailsTestEventPublisher eventPublisher)` Performs the tests, and appropriately calls eventPublisher to communicate the status.
    `protected void` | `eachSourceFile(groovy.lang.Closure body)` Calls `body` with the GrailsTestTargetPattern that matched the source, and the File for the source.
    `protected java.util.Collection<java.io.File>` | `findSourceFiles(GrailsTestTargetPattern targetPattern)` Finds source based on the `testSuffixes` and `testExtensions` that match the `targetPattern`.
    `protected org.springframework.context.ApplicationContext` | `getApplicationContext()` Will return the application context if it is present, but will throw an IllegalStateException if it is not.
    `protected java.io.File` | `getSourceDir()` The location of this type's source
    `protected java.lang.ClassLoader` | `getTestClassLoader()` A class loader with class path additions of this type's source dir and compile classed dir.
    `protected java.util.List<java.lang.String>` | `getTestExtensions()` Override to have the tests for this type require a certain file extension
    `protected java.util.List<java.lang.String>` | `getTestSuffixes()` Override to have the tests for this type require a certain suffix
    `protected java.lang.Class` | `loadClass(java.lang.String className)` Loods the class named by `className` using a class loader that can load the test classes, throwing a RuntimeException if the class can't be loaded.
    `int` | `prepare(GrailsTestTargetPattern[] testTargetPatterns, java.io.File compiledClassesDir, groovy.lang.Binding buildBinding)` Sets the appropriate instance variables from the parameters, and calls doPrepare()
    `GrailsTestTypeResult` | `run(GrailsTestEventPublisher eventPublisher)` Sets the current thread's contextClassLoader to the test class loader, calls doRun(GrailsTestEventPublisher) and then restores the original contextClassLoader.
    `protected java.lang.Class` | `sourceFileToClass(java.io.File sourceFile)` Convenience method for obtaining the class file for a test class
    `protected java.io.File` | `sourceFileToClassFile(java.io.File sourceFile)` Convenience method for obtaining the class file for a test class
    `protected java.lang.String` | `sourceFileToClassName(java.io.File sourceFile)` Gets the corresponding class name for a source file of this test type.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Property Detail

    - #### groovy.lang.Binding buildBinding

      The binding from the build environment

    - #### java.io.File compiledClassesDir

      The location where the type's source was compiled to

    - #### final java.lang.String name

      The name of this test type

    - #### final java.lang.String relativeSourcePath

      The path to this type's source, relative to the root of all test source

    - #### GrailsTestTargetPattern[] testTargetPatterns

      The test target patterns that should be used to filter the tests to run

  - ### Constructor Detail

    - #### GrailsTestTypeSupport(java.lang.String name, java.lang.String relativeSourcePath)

      Sets the name and relativeSourcePath

  - ### Method Detail

    - #### void cleanup()

      Called after the tests have completed, regardless of success or not. This implementation does nothing.

    - #### protected SystemOutAndErrSwapper createSystemOutAndErrSwapper()

      Creates swapper with echo parameters based on testOptions.echoOut and testOptions.echoErr in the build binding.

    - #### protected int doPrepare()

      Do any preparation and return the (approximate) number of tests that will be run. If a number less than 1 is returned, this test type will not be run. Typically, implementations with call getTestClassLoader() and load the appropriate tests that match the `testTargetPatterns`.

    - #### protected GrailsTestTypeResult doRun(GrailsTestEventPublisher eventPublisher)

      Performs the tests, and appropriately calls eventPublisher to communicate the status.

    - #### protected void eachSourceFile(groovy.lang.Closure body)

      Calls `body` with the GrailsTestTargetPattern that matched the source, and the File for the source.

    - #### protected java.util.Collection<java.io.File> findSourceFiles(GrailsTestTargetPattern targetPattern)

      Finds source based on the `testSuffixes` and `testExtensions` that match the `targetPattern`.

    - #### protected org.springframework.context.ApplicationContext getApplicationContext()

      Will return the application context if it is present, but will throw an IllegalStateException if it is not. This should only be called when Grails is bootstrapped up (i.e. not for unit tests)

    - #### protected java.io.File getSourceDir()

      The location of this type's source

    - #### protected java.lang.ClassLoader getTestClassLoader()

      A class loader with class path additions of this type's source dir and compile classed dir. Note: should not be called before prepare is called by the testing system.

    - #### protected java.util.List<java.lang.String> getTestExtensions()

      Override to have the tests for this type require a certain file extension This implementation returns ["groovy", "java"]

    - #### protected java.util.List<java.lang.String> getTestSuffixes()

      Override to have the tests for this type require a certain suffix This implementation returns [""] (i.e. no required suffix)

    - #### @groovy.transform.CompileStatic protected java.lang.Class loadClass(java.lang.String className)

      Loods the class named by `className` using a class loader that can load the test classes, throwing a RuntimeException if the class can't be loaded.

    - #### @groovy.transform.CompileStatic int prepare(GrailsTestTargetPattern[] testTargetPatterns, java.io.File compiledClassesDir, groovy.lang.Binding buildBinding)

      Sets the appropriate instance variables from the parameters, and calls doPrepare()

    - #### @groovy.transform.CompileStatic GrailsTestTypeResult run(GrailsTestEventPublisher eventPublisher)

      Sets the current thread's contextClassLoader to the test class loader, calls doRun(GrailsTestEventPublisher) and then restores the original contextClassLoader.

    - #### @groovy.transform.CompileStatic protected java.lang.Class sourceFileToClass(java.io.File sourceFile)

      Convenience method for obtaining the class file for a test class

    - #### @groovy.transform.CompileStatic protected java.io.File sourceFileToClassFile(java.io.File sourceFile)

      Convenience method for obtaining the class file for a test class

    - #### @groovy.transform.CompileStatic protected java.lang.String sourceFileToClassName(java.io.File sourceFile)

      Gets the corresponding class name for a source file of this test type.