time-test is a lightweight framework for testing time-based functionality.
|Public Maven repo||https://bintray.com/devexperts/Maven/time-test|
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:
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:
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.
XXXTimeProvider.start() to start using it. Don't forget to reset TimeProvider to default. Use
XXXTimeProvider.reset() for this.
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.inscreaseTime(millis) to change current time. Use
TestTimeProvider.waitUntilThreadsAreFrozen to wait until all threads complete their work.
You can pass your own configuration in
timetest.properties properties file or set these properties as system parameters (*-Dparam.name=value*). The
timetest.properties 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
package.to.transform.*,another.package.to.transform.*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.
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: