Page tree

Get started by adding some pages to this space. Create page.

Skip to end of metadata
Go to start of metadata

time-test is a lightweight framework for testing time-based functionality.



time-test is a framework for testing time-based functionality.

Sometimes you have code with similar logic: "wait for 30 seconds and then do something if no changes have been detected".

If you want to test such logic you can write something like this:

Thread.sleep(30_000 + 200);

However, such tests are undesirable to be in the project. Also what if you want to test logic which should be executed once per month? Or what if this "something doing" hasn't done before the check starts?

time-test provides an easy way to test such logic. For example, the code above can be written more clear:

TestTimeProvider.waitUntilThreadsAreFrozen(200 /*ms*/);

And this test doesn't do superfluous work.

time-test instruments byte-code and change time-based methods invocations (such as System.currentTimeMillis, Object.wait, Unsafe.park) to our own implementation.


This interface provides an implementation of time-based methods. The default implementation forwards all calls to standard system methods.

Use XXXTimeProvider.start() to start using it. Don't forget to reset TimeProvider to default. Use XXXTimeProvider.reset() for this.


DummyTimeProvider throws UnsupportedOperationException on all method calls. It should be used for testing functionality which does not depend on time.


TestTimeProvider provides full access on time. Use TestTimeProvider.setTime(millis) and TestTimeProvider.inscreaseTime(millis) to change current time. Use TestTimeProvider.waitUntilThreadsAreFrozen to wait until all threads complete their work.


You can pass your own configuration in properties file or set these properties as system parameters (**). The file should be in the application classpath.

  • timetest.tests - defines test entrance classes in glob format. Usually, test classes. Default value: *Test (all classes with suffix Test)
  • timetest.log.level defines internal logging level. Possible values: DEBUG, INFO (default value), WARN, ERROR.
  • timetest.log.file defines path of file to be used for logging. By default logs are printed to the standard output.
  • timetest.cache.dir [experimental] defines directory to be used for transformed classes caching. This feature is unstable, use it on your own risk.
  • timetest.include defines the transformation scope using globs. For example, setting the value to*,* informs time-test to transform classes from these packages only. By default all classes are included.
  • timetest.exclude defines the classes which should be excluded from transformation. The syntax is similar to timetest.include option.


Time-test is implemented as java agent and you should copy it to build directory and configure maven-surefire-plugin to use it for tests.

    <!-- maven-dependency-plugin is used to copy "timetest" agent into target directory -->
    <!-- Configure maven-surefire-plugin to use "timetest" agent -->

Usage example

public void setUp() {

public void tearDown() {

@Test(timeout = 100)
public void testSleepWithTestTimeProvider() {
    Thread t = new Thread(() -> {
        // Do smth
        int sum = 0;
        for (int i = 0; i < 100_000; i++)
            sum += i;
        // Sleep


If you need help, you have a question, or you need further details on how to use time-test, you can refer to the following resources:

You can use the following e-mail to contact us directly:


  • No labels