public abstract class BaseTest extends Object
Parent class that can be used as the parent of any class containing JUnit tests.
It provides logging to Logger for the the start and end of each Test,
along with elapsed time and details of any failed tests. Log entries are made to the category
of the implementing child class, and the same logger is made available for use to child classes
as logger.
Test classes may wish to save outputs for later inspection, etc. The getTestOutput()
method and related methods provide a convenient way to obtain an appropriate directory for storing
these outputs, rooted at getTestOutputRoot() by default, combined with additional
sub-directories to match the package structure of the calling class.
To ensure clean test runs, the default afterLogCheck() checks for any warnings or errors
reported to the ILogChecker configured to TestThreadData.setLogChecker(ILogChecker)
and will throw an AssertionError if any warnings or errors were reported as logged.
This requires TestLogWatcherAppender to be configured
as a logging appender, typically in logback-test.xml.
Unless a Test is annotated with an Test.expected() exception, or unless a separate
LogChecker annotation is used, an instance of NoWarningsLogChecker is used by default.
Otherwise, an instance of IgnoreLogChecker is used as an empty implementation.
| Modifier and Type | Class and Description |
|---|---|
protected class |
BaseTest.BaseTestWatcher |
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
protected TestThreadData |
testThreadData |
BaseTest.BaseTestWatcher |
watchman |
| Constructor and Description |
|---|
BaseTest() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterLogCheck() |
protected File |
getTestOutput()
Returns the default directory to use for saving test outputs for the current class.
|
protected static File |
getTestOutput(File root,
Class<?> c)
Returns a directory of the specified root combined with additional subdirectories to match the
package structure of the specified class.
|
protected File |
getTestOutputRoot()
Returns the default directory root to use for saving test outputs.
|
protected final org.slf4j.Logger logger
protected final TestThreadData testThreadData
public final BaseTest.BaseTestWatcher watchman
protected File getTestOutputRoot()
Returns the default directory root to use for saving test outputs.
Defaults to "target/JUnit", may be overridden.
Directory is not created if it does not exist.
Most callers should call getTestOutput() instead.
protected File getTestOutput()
Returns the default directory to use for saving test outputs for the current class.
This is a convenience method that calls getTestOutput(File, Class) with
getTestOutputRoot() and Object.getClass().
Most callers should call this method.
protected static File getTestOutput(File root, Class<?> c)
Returns a directory of the specified root combined with additional subdirectories to match the package structure of the specified class. Directory is not created if it does not exist.
Most callers should call getTestOutput() instead.
Copyright © 2017 Mark A. Ziesemer. All rights reserved.