saker.java.testing Documentation TaskDoc JavaDoc Packages
public abstract class BasicJavaTestingInvoker implements JavaTestingInvoker
Basic JavaTestingInvoker implementation that sets up the ClassLoaders and other testing related environment.

The test invoker will properly initialize the classloaders that can be used to load the user and test classes. It is an abstract class that should be subclassed to specialize how the testing is performed.

When a test is executed, the class will synchronize on BasicJavaTestingInvoker.class and acquire an exclusive lock during the invocation of a test case. It will replace the standard I/O fields in System, and reset the system properties.

It will also set the thread context classloader to the test classloader. The standard I/O is buffered, and will be set as the failure information of the test result.

When a test execution is over, the class restores the mocked system fields.

Clients should subclass this class.

Constructors
public
Creates a new testing invoker.
Methods
public void
Closes this test invoker.
protected ClassLoader
Creates the test classloader.
protected ClassLoader
Creates the user classloader.
protected final ClassLoader
Gets the test classloader.
protected final ClassLoader
Gets the test runner classloader.
protected final ClassLoader
Gets the user classloader.
public void
initClassLoaders(ClassLoader userclassloaderparent, ClassLoaderDataFinder[] userclasspath, ClassLoader testclassloaderparent, ClassLoaderDataFinder[] testclasspath)
Requests the test invoker to perform the initialization of the ClassLoaders for the user and test classpath.
public void
initTestRunner(ClassLoader testrunnerclassloader, TestInvokerParameters parameters)
Initializes the test runner.
public final JavaTestInvocationResult
Invokes a test case.
protected abstract JavaTestInvocationResult
Invokes the test.
Creates a new testing invoker.
public void close() throws IOException
Overridden from: JavaTestingInvoker
Closes this test invoker.

This method is called when no more test are executed using this invoker.

The test invoker should clean up any possible resources that were allocated by the test cases.

Closes this stream and releases any system resources associated with it.If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable.close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

IOExceptionif an I/O error occurs
Creates the test classloader.

Clients may override to perform custom initialization.

parentThe parent for the test case classes. (May be null.) This is not the same as in initClassLoaders, but a classloader that provides access to the user classloader and test runner classloader as well.
testclasspathThe data finders for the test classpath.
The test classloader.
Creates the user classloader.

Clients may override to perform custom initialization.

parentThe parent for the user classes. (May be null.) This is the same as passed to initClassLoaders.
userclasspathThe data finders for the user classpath.
The user classloader.
Gets the test classloader.

The test classloader contains the test case classes.

The classloader.
Gets the test runner classloader.

The test runner classloader contains the classes for the used testing framework.

The classloader.
Gets the user classloader.

The user classloader contains the classes being tested.

The classloader.
public void initClassLoaders(ClassLoader userclassloaderparent, ClassLoaderDataFinder[] userclasspath, ClassLoader testclassloaderparent, ClassLoaderDataFinder[] testclasspath)
Overridden from: JavaTestingInvoker
Requests the test invoker to perform the initialization of the ClassLoaders for the user and test classpath.

This method is called after JavaTestingInvoker.initTestRunner(ClassLoader, TestInvokerParameters).

The user class loader is the one that contains the classes being tested. The test class loader is the one that contains the test cases.

The relations between the constructed classloaders may be implementation dependent for the test invoker. However, we recommend that the user classloader is constructed with the specified parent as its parent, and the test classloader is constructed with the specified parent, the user classloader, and the test runner classloader as its parent. The BasicJavaTestingInvoker class initializes them this way.

userclassloaderparentThe classloader that should be the part of the parents of the user classpath. (May be null.)
userclasspathThe data finders for the user classpath.
testclassloaderparentThe classloader that should be the paret of the parents of the test classpath. (May be null.)
testclasspathThe data finders for the test classpath.
public void initTestRunner(ClassLoader testrunnerclassloader, TestInvokerParameters parameters) throws JavaTestRunnerFailureException
Overridden from: JavaTestingInvoker
Initializes the test runner.

This method is called first as part of the initialization.

The method should perform the operations that required in order to locate the test runner that will execute the tests. This can be done in an implementation dependent way.

In common implementations, the method will attempt to load a class that will be called with the test classes as its input in the JavaTestingInvoker.invokeTest(JavaTestingFileProvider, TestInvocationParameters) method.
One example for this may be that is to find the entry point of the testing framework that contains a main method. That main method is caleld for each test in invokeTest.

testrunnerclassloaderThe ClassLoader that is used to load the test runner classes. May be the same as the classloader of this testing invoker.
parametersThe test invoker parameters that are passed by the user as configuration.
JavaTestRunnerFailureExceptionIf the initialization failed-
Overridden from: JavaTestingInvoker
Invokes a test case.

This method is called after the initialization was performed.

The test invoker should invoke the test class specified with the given parameters. It may do so in an implementation dependent manner.

The file provider parameter can be used by test case instrumentation to request files that are being accessed by the test cases. The BasicInstrumentationJavaTestInvoker subclass handles it appropriately.

The result of the test is returned from this function. Exceptions thrown by the test cases shouldn't be relayed to the caller. The test result object should contain any failure information. It can also be used to report the dependencies of the test case.

fileproviderThe testing file provider. (May be null.)
parametersThe invocation parameters for the test case. The test class name can be retrieved using TestInvocationParameters.getTestClassName().
The test invocation result.
JavaTestRunnerFailureExceptionIf the test runner encountered a failure during the invocation of the test.
Invokes the test.

This method is called by invokeTest(JavaTestingFileProvider, TestInvocationParameters) after the environment has been initialized for the test case.

The arguments are the same as for the invokeTest method.

fileproviderThe testing file provider. (May be null.)
parametersThe invocation parameters for the test case. The test class name can be retrieved using TestInvocationParameters.getTestClassName().
The test invocation result.
JavaTestRunnerFailureExceptionIf the test runner encountered a failure during the invocation of the test.