How to use camunda-bpm-assert in a project

395 views
Skip to first unread message

kanschik...@googlemail.com

unread,
Jan 17, 2014, 5:04:55 AM1/17/14
to camunda-...@googlegroups.com
Hi all,

I would like to do unit testing for bpm processes and mock the delegats using mockito. I understand that this should (or can) be done with camunda-bpm-assert.

However, I'm missing any information about how to use it ;-(

Is there any example of a working setup? Is there already a pom in the repository?

Thanks and regards,

Jens Kanschik.

Martin Schimak

unread,
Jan 17, 2014, 10:15:00 AM1/17/14
to camunda-...@googlegroups.com
Hi Jens,

Thank you for your interest in camunda-bpm-assert! Let me ask you for a bit of caution: this project is these days undergoing a restructuring - in particular it will be limited to just one concern: the assertions - therefore the concern of mocking as still described in the old fest-assertions user guide is outdated! Just the front page README of that community extension is updated since yesterday. You will find the "Getting started" coordinates there: maven dependencies, the static import you need and a basic example: https://github.com/camunda/camunda-bpm-assert

I am literally NOW working on a more detailed guide so it will continuously change today, Monday ff. Thank you for your patience!-)

However, I think your primary concern is mocking. Here is a pointer to how mocking can be done - it's still in the fox user guide, but the described functionality continues to be available in the camunda BPM engine core: https://app.camunda.com/confluence/display/foxUserGuide/Using+Mocks+to+test+your+Process+Application

This style of mocking can be easily combined with using the assertions. Inside camunda-bpm-assert, you find an example in which BOTH assertions and mocking according to the above mentioned mocking guide are used:


I hope this helps!

Many greetings,
Martin.
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.

kanschik...@googlemail.com

unread,
Jan 20, 2014, 12:02:47 PM1/20/14
to camunda-...@googlegroups.com, kanschik...@googlemail.com
Hi,

By now, I think my problems with unit testing are rather related to a problem with timer events and setting the current time in unit tests.

In general, I can test and mock delegates as described in your link. However, as soon as I add a timer event, I get strange errors.

Would you mind to check out the small demo project at https://github.com/jkanschik/camunda-timer-test ?

There are two tests: one is working, but without a timer event. The second is not working - there is a strange error that the expression cannot be resolved:
Unknown property used in expression: #{loggerDelegate.doSomething()}. Cause: Cannot resolve identifier 'loggerDelegate'

Since the service tasks and the setup in both processes is identical, the problem seems to be related to the timer.

Am I doing something wrong using "setCurrentTime()" or is there some bug?

Regards,

Jens.

Martin Schimak

unread,
Jan 20, 2014, 12:45:40 PM1/20/14
to camunda-...@googlegroups.com
Hi Jens,

I had a quick look at your code. Without having tested my assumption, I assume that the problem most probably is that you implicitly start a job executor by calling TestHelper.waitForJobExecutorToProcessAllJobs. The job executor will retrieve the (timer) job and try to execute the subsequent service task (that it does so you can see in your failure message). However, the job executor then fails to resolve the name of the mocked service, because Mocks.register("loggerDelegate", loggerDelegate) binds this name to the current thread (by using a ThreadLocal), but the job executor is executing the timer job and the subsequent service task in another thread.

Mocks.register is meant to be used in a purely single-threaded, no-job-executor, "unit test" environment. In such an environment, instead of setting the time and waiting for the job executor to process the jobs, you need to explicitly trigger the timer job in your own testing thread:

    Job job = processEngineRule.getManagementService().createJobQuery().singleResult();
    processEngineRule.getManagementService().executeJob(job.getId());

Then it should happily resolve the name and should work.

Many greetings,
Martin.

On 20.01.2014 18:02:47, (null) <kanschik...@googlemail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.

kanschik...@googlemail.com

unread,
Jan 21, 2014, 4:18:28 AM1/21/14
to camunda-...@googlegroups.com
Hi Martin,

Your two lines of code solved the problem, thanks a lot. I saw that Mocks.register() registers the mocks in a thread local variable (mockContainer), so your explanation makes sense. I just had no clue how to resolve the problem ;-)

I will push the fixed code to github.

Regards,

Jens.

Reply all
Reply to author
Forward
0 new messages