Hi there,
How do you recommend the testing of processes with timer events? Let’s say we have a timer event set to be triggered in 10 days from process instance start. How do you test the process works as expected?
Cristian
Hi there,
How do you recommend the testing of processes with timer events? Let’s say we have a timer event set to be triggered in 10 days from process instance start. How do you test the process works as expected?
Cristian
Hi Cristian,
you can use the ClockUtil class.
For example to increment the time with the seconds of ten days use:
long time = ClockUtil.getCurrentTime().getTime();
long seconds = 10 * 24 * 60 * 60;
ClockUtil.setCurrentTime(new Date(time + seconds * 1000));
Greets,
Chris
In a JUnit -Test, you have to call managementService.executeJob(jobId)
(https://docs.camunda.org/javadoc/camunda-bpm-platform/7.6/org/camunda/bpm/engine/ManagementService.html#executeJob(java.lang.String)) to fire the timer immediatly.
If you use the bpm-assert community extension in your JUnit-Tests, then execute(job())
(https://github.com/camunda/camunda-bpm-assert/blob/master/camunda-bpm-assert/README.md#helpers-execute) is enough.
Hope this helps, Ingo
Hi Christian,
Testing is an interesting topic- what do you really want to test?
Do you want to test;
The answer to this may influence how you build your test case.
regards
Rob
@Rob: Number 3 in your list, but generally speaking, almost everything is a candidate for testing.
For completeness:
Keep in mind that you have to enable the Job Executor to use timers, otherwise the ClockUtil code will have no effect.
https://docs.camunda.org/manual/7.6/reference/bpmn20/events/timer-events
Thanks for posting the question and the answer. It was very helpful.