abstract class GrailsTestTypeSupport extends java.lang.Object
Provides a convenient base for GrailsTestType implementations.
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 and description |
---|
GrailsTestTypeSupport
(java.lang.String name, java.lang.String relativeSourcePath) Sets the name and relativeSourcePath |
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. |
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() |
The binding from the build environment
The location where the type's source was compiled to
The name of this test type
The path to this type's source, relative to the root of all test source
The test target patterns that should be used to filter the tests to run
Sets the name and relativeSourcePath
Called after the tests have completed, regardless of success or not. This implementation does nothing.
Creates swapper with echo parameters based on testOptions.echoOut and testOptions.echoErr in the build binding.
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
.
Performs the tests, and appropriately calls eventPublisher to communicate the status.
Calls body
with the GrailsTestTargetPattern that matched the source, and the File for the source.
Finds source based on the testSuffixes
and testExtensions
that match the targetPattern
.
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)
The location of this type's source
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.
Override to have the tests for this type require a certain file extension This implementation returns ["groovy", "java"]
Override to have the tests for this type require a certain suffix This implementation returns [""] (i.e. no required suffix)
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.
Sets the appropriate instance variables from the parameters, and calls doPrepare()
Sets the current thread's contextClassLoader to the test class loader, calls doRun(GrailsTestEventPublisher) and then restores the original contextClassLoader.
Convenience method for obtaining the class file for a test class
Convenience method for obtaining the class file for a test class
Gets the corresponding class name for a source file of this test type.
Groovy Documentation