Testing Time in Java by Joep Weijers
1,162 views · Published 11 November 2016 · 12:09 · Indexed 28 October 2026
Channel: Devoxx · 2016 · Science & Technology
We all know we should have unit tests for most of our code. And unit tests should be fast and system independent in order to give reproducible results. But how do you test your functionalities that are depending on time? You don't because it is too difficult? You test it manually, changing the actual time of your computer? Or did you check StackOverflow and read that you need to replace all your System.currentTimeMillis() calls to a custom implementation? Java 8 introduced java.time.Clock for this purpose, but what if you have a big legacy application and it is infeasible to introduce yourOwnCurrentTimeMillis? Enter the TimeTransformer. A small open source utility using bytecode weaving to rewire all calls to System.currentTimeMillis(). It provides an API to completely alter the time of a JVM, making time travel in your applications and unit tests possible. I will demonstrate the TimeTransformer on a small webserver where I want to verify that given I am locked out after too many incorrect password attempts, when the lock-out-time has elapsed, then I can log in again. Joep Weijers is a Build Master at TOPdesk with a keen interest in delivering quality software continuously. He loves playing around with Jenkins Pipelines, Selenium, Docker and keeps in touch with his inner developer by educating his colleagues on testable Java code. [HGJ-2011]
More from this channel
-
32:13
Writing Groovy AST Transformations: Getting Practical in an hour! by Baruch Sadogursky
-
25:58
TweetWallFX - Behind the Scenes by Sven Reimers
-
29:44
Second generation "workflow managers" for big data by Alex Van Boxel
-
29:13
Secrets are secrets. Please maintain them as secrets by Alex Soto
-
2:13:40
JavaScript build pipelines with Gulp.js by Stefan Baumgartner
-
2:04:09
Powerful Metaprogramming Techniques With Groovy by Jeff Brown
-
2:38:32
Distributed Machine Learning 101 using Apache Spark from a Browser by Xavier Tordoir/Andy Petrella
-
2:36:21
Caching 101: Caching on the JVM (and beyond) by Alex Snaps/Louis Jacomet