Time dependent unit tests braking when run in parallel, any workarounds?
I have time dependent unit tests in which I have to simulate "now". I use
JodaTime and when I need to simulate the value of now for purposes of time
dependent testing I use DateTimeUtils.setCurrentMillisFixed(...), as
suggested in the accepted answer in question Time dependent unit tests.
However, this has now caused problems when unit tests are run in parallel
as one test is changing other test's simulated value of now. Proper
solution would be to make all classes obtain current time from a Clock
dependency which could be mocked out in tests (as suggested in most
upvoted answer in Time dependent unit tests). However, I will not have
enough development resources to make that refactoring effort at the
moment.
My question is is there a way to work around this by somehow specifying
which tests may be run in parallel and which may not? Is there a way to
work around this by using DateTimeUtils.setCurrentMillisProvider() ?
Testing framework is JUnit4, tests are run from maven.
No comments:
Post a Comment