Constructs a TestRunner
with the specified verbosity level.
One of the values from TestRunner.VERBOSITY
(default: HEADER(1)
)
Static
Readonly
VERBOSITYAllowed verbosity levels, to control the output of TestRunner.title
method.
Executes a test case with a title and handles assertions.
This method logs the start and end of the test case with titles (using TestRunner.title
method)
if the verbosity level allows it.
It executes the provided function which should contain assertions.
If an assertion fails, it will throw an AssertionError
.
See detailed JSDoc in class documentation
The name of the test case.
The function containing the test logic. It should contain assertions using Assert
methods.
Indentation level for the title (default: 2(SECTION)
). The indentation level is indicated
with the number of suffix *
.
AssertionError - If an assertion fails within the test function fn. - If the provided fn is not a function.
Returns the current verbosity level.
TestRunner.VERBOSITY
.const runner = new TestRunner(TestRunner.VERBOSITY.HEADER)
console.log(runner.getVerbosity()) // Outputs: 1
Returns the corresonding string label for the verbosity level. This is useful for logging or debugging purposes.
const runner = new TestRunner(TestRunner.VERBOSITY.HEADER)
console.log(runner.getVerbosityLabel()) // Outputs: "HEADER"
Conditionally prints a title message based on the configured verbosity.
The title is prefixed and suffixed with *
characters for visual structure.
The number of *
will depend on the indentation level, for 2
it shows
**
as prefix and suffix.
The message to display
Indentation level (default: 1(HEADER)
). The indentation level is indicated
with the number of *
characters used as prefix and suffix to the title.
const runner = new TestRunner(TestRunner.VERBOSITY.HEADER)
runner.title("My Test Section", 2) // Outputs: "** My Test Section **"
This method is used to create structured output for test sections or titles. It helps in organizing test output visually, especially when running multiple tests. The indentation level allows for hierarchical organization of test cases.
A utility class for managing and running test cases with controlled console output.
TestRunner
supports configurable verbosity levels and allows structured logging with indentation for better test output organization. It is primarily designed for test cases using assertion methods (e.g.,Assert.equals
,Assert.throws
). Verbosity can be set via theTestRunner.VERBOSITY
in the constructor: constant object (enum pattern)OFF
(0): No outputHEADER
(1): High-level section headers onlySECTION
(2): First level nested titleSUBSECTION
(3): Second level nested titleVerbosity level is incremental, i.e. allows all logging events with indentation level that is lower or equal than
TestRunner.VERBOSITY
.Example
Remarks
Assert
methods internally. If an assertion fails, the error will be caught and reported with context.TestCase
class where each test case scenario is defined with a static method.