How to create focused unit tests for complex models


Is it possible to create unit tests for only a given section of a model by defining the beginning and the end of the test?

I found
runtimeService().createProcessInstanceByKey("...").startBeforeActivity("...activity id ...")
that allows starting the test at any given point of the model, which is great.

Is it possible to ignore the rest of the model after a given activity?
I also found

This seems to be very handy too, but what can I do if my model does not have user tasks and all the rest of the model gets executed before I could get the execution back?

Thank you very much for your suggestions.


I’d recommend directly invoking your task implementations (e.g. delegate implementations).

This implies that you’re discretely testing various sub-sets of the model.


Hi @janigabor,

You can start the test with the help of process instance modification api whereever you want: [1]


The process always runs until the next wait state [2]. You can go further by completing the task or assert the desired result here.


Cheers, Ingo


That’s exactly the point. I don’t want my process to go on with execution after a given point. But I don’t have user tasks so it does not go into wait state.

So is there a way to modify the process dynamically? Remove activities from it that I don’t want to test perhaps?

Or is there a better approach to create a focused unit test for a part of a process?

Thank you.


Hello @janigabor,

may it help to mark the last activity or event of the test with ‘async after’?

If you want to do it for the test only, you can use the model-api to change the model before the deployment.

Does it help you?


I had hoped for a better solution, but this works too.