saker.java.testing Documentation TaskDoc JavaDoc Packages
public interface JavaTestingInvoker extends Closeable
Handles one or multiple Java test invocations.

The JavaTestingInvoker interface is the manager object that executes the Java test invocations. At the start of testing it is initialized, then asked to run each test case, and closed at the end of testing.

The test invoker is initialized with the ClassLoaders that make the classes being part of the testing accessible to the test invoker. The test invoker can decide to manage the test execution in an implementation dependent way.

The test invoker is considered to be an overall environment provider during the testing. It is a stateful object and test implementations may access various aspects of the test invoker. The test invoker should be accessible to the test case classes.

Clients may implement this interface. However, they are recommended to extend one of the basic test invoker API classes that integrate with the incremental testing instrumentation of the build task. See BasicInstrumentationJavaTestInvoker.

Implementations must have a public no-arg constructor.

Methods
public default void
Closes this test invoker.
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 JavaTestInvocationResult
Invokes a test case.
public default void close() throws IOException
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
public abstract 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.

This method is called after 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 abstract void initTestRunner(ClassLoader testrunnerclassloader, TestInvokerParameters parameters) throws JavaTestRunnerFailureException
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 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-
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.