Testing timer events in processes

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

1 Like

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

3 Likes

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

6 Likes

Hi Christian,

Testing is an interesting topic- what do you really want to test?

Do you want to test;

  1. if the engine’s handling of the timer construct is correct?
  2. if your configuration for 10 days is correct?
  3. the behaviour of your process after the timer event fires?

The answer to this may influence how you build your test case.

regards

Rob

2 Likes

@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.

2 Likes