Groovy Documentation

## org.codehaus.groovy.grails.test.support
[Groovy] Class GrailsTestTypeSupport

    java.lang.Object
      org.codehaus.groovy.grails.test.support.GrailsTestTypeSupport

    abstract class GrailsTestTypeSupport

Provides a convenient base for GrailsTestType implementations.

Property Summary
`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
`GrailsTestTypeSupport(java.lang.String name, java.lang.String relativeSourcePath)` Sets the name and relativeSourcePath

Method Summary
`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 GrailsTestEventPublisher 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.List` | `findSourceFiles(GrailsTestTargetPattern targetPattern)` Finds source based on the `testSuffixes` and `testExtensions` that match the `targetPattern`.
`protected 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` | `getTestExtensions()` Override to have the tests for this type require a certain file extension
`protected java.util.List` | `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.

Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), 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

### buildBinding

    groovy.lang.Binding buildBinding

  The binding from the build environment

### compiledClassesDir

    java.io.File compiledClassesDir

  The location where the type's source was compiled to

### name

    final java.lang.String name

  The name of this test type

### relativeSourcePath

    final java.lang.String relativeSourcePath

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

### testTargetPatterns

    GrailsTestTargetPattern testTargetPatterns

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

Constructor Detail

### GrailsTestTypeSupport

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

  Sets the name and relativeSourcePath

Method Detail

### cleanup

    void cleanup()

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

### createSystemOutAndErrSwapper

    protected SystemOutAndErrSwapper createSystemOutAndErrSwapper()

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

### doPrepare

    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`.

### doRun

    protected GrailsTestTypeResult doRun(GrailsTestEventPublisher eventPublisher)

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

### eachSourceFile

    protected void eachSourceFile(groovy.lang.Closure body)

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

### findSourceFiles

    protected java.util.List findSourceFiles(GrailsTestTargetPattern targetPattern)

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

### getApplicationContext

    protected 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)

### getSourceDir

    protected java.io.File getSourceDir()

  The location of this type's source

### getTestClassLoader

    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.

### getTestExtensions

    protected java.util.List getTestExtensions()

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

### getTestSuffixes

    protected java.util.List getTestSuffixes()

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

### loadClass

    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.

### prepare

    int prepare(GrailsTestTargetPattern[] testTargetPatterns, java.io.File compiledClassesDir, groovy.lang.Binding buildBinding)

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

### run

    GrailsTestTypeResult run(GrailsTestEventPublisher eventPublisher)

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

### sourceFileToClass

    protected java.lang.Class sourceFileToClass(java.io.File sourceFile)

  Convenience method for obtaining the class file for a test class

### sourceFileToClassFile

    protected java.io.File sourceFileToClassFile(java.io.File sourceFile)

  Convenience method for obtaining the class file for a test class

### sourceFileToClassName

    protected java.lang.String sourceFileToClassName(java.io.File sourceFile)

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

Groovy Documentation