Today I was doing unit tests for one Activiti flow. In the end of the test I wanted to assert value of output variable of that flow.
To set the variable, you can do it in following ways:
- Do it in the script:
- User service task, which puts service result in execution variable
- In java service delegate again using:
In order to test variable, we need to use history service:
Basically as the flow execution is finished, the only way we can obtain value of the variable is to use HistoryService and to do query by processInstanceId and variable name.
All is good and well, untill actually in your flow you do multiple assignments to same variable. I was having problems, as there were multiple history entries. Apparently Activiti saves full history of changes. So in order to get last value (if presumably this is what you need), code needs to be changed.