Testing Utilities

GitLab Docs Pipeline Coverage
Utilities for testing. See morimekta.net/utils for procedures on releases.

Testing

This module contains a number of utilities and helpers to help with testing. It consists of a number of mostly independent parts.

Concurrency Utils

  • FakeClock: A fake java.time.Clock that keeps constant time and is ticked manually.
  • FakeScheduledExecutor: A scheduled executor that uses a fake clock and 'ticking' of that to trigger scheduled tasks. Using a real executor in the background.
  • ImmediateExecutor: A fake executor that executes tasks when they are submitted. This means they run while waiting for submit to return, so all tasks are completed immediately.
  • ImmediateScheduledExecutor: A fake scheduled executor that uses a fake clock and 'ticking' of that to trigger scheduled tasks in the same thread as triggers the tick. Submitted tasks are always handled in the tick listener.

Console Utils

  • Console: An interface to interact with a console during testing.
  • ConsoleManager: Base class for managing a fake console during testing that will capture whats written to standard OUT and ERR and replace standard IN.

Text Utils

  • EnglishWords: A super-light text and word generator.

JUnit 4

  • ConsoleWatcher: A junit4 @Rule to set up and reset the console.
  • DataProviderUtil: Utility for generating matrices of arguments to from a data provider using com.tngtech.java:junit-dataprovider.

JUnit 5

  • ConsoleExtension: A junit5 extension to set up and reset the console, and give access to Console and TTY parameters.
  • ParamsProviderUtil: Utility for generating matrices of arguments to from a params provider.

Major Version Changes

  • 4.x -> 5.x: FakeScheduledExecutor renamed ImmediateScheduledExecutor and new FakeScheduledExecutor created using a real background executor, but using the fake clock to trigger the scheduled tasks.