cancel
Showing results for 
Search instead for 
Did you mean: 

[Sticky] How to write a unit test

jbarrez
Star Contributor
Star Contributor
When encountering a bug in Activiti, the easiest way to reach the Activiti team and see it fixed is to create an issue in the Activiti Jira (http://jira.codehaus.org/browse/ACT).

Of course, a good description on how to reproduce the problem is crucial. But to make it really interesting for us (and to speed up things), the issue is accompanied by a unit test demonstrating the problem.

To simplify this process, we've created a 'unit test template' project which you can use: https://github.com/Activiti/activiti-unit-test-template
Add your failing unit test, zip up the project and attach it to the issue.

More about this template, read http://www.jorambarrez.be/blog/2012/09/24/how-to-write-a-unit-test/
27 REPLIES 27

jbarrez
Star Contributor
Star Contributor
That error shouldn't happen, as it's all in memory…. there is no existing database.
Did you simply just download and ran it? Or did you do modifications?

yongqiang
Champ in-the-making
Champ in-the-making
Hi jbarrez,

Thank you for your confirmation.
Yes, I did some modification to the given template to work with existing spring configuration. The existing spring configuration have db configuration. Therefore, it report issue.

Best Regards,
Yong Qiang

jbarrez
Star Contributor
Star Contributor
Well, then I would need to see that configuration to know why it's failing … 😉

ashish46
Champ in-the-making
Champ in-the-making
Thanks for sharing.A unit test is code that exercises a specific portion of your codebase in a particular context. Typically, each unit test sends a specific input to a method and verifies that the method returns the expected value, or takes the expected action. Unit tests prove that the code you are testing does in fact do what you expect it to do.

gribo
Champ in-the-making
Champ in-the-making
Hi,

Is there a sample unit-test with ELProperty in the bmnp.xml file and spring bean ? I'm stuck with the same issue as there :

http://forums.activiti.org/content/unknown-property-used-expression-cannot-resolve-identifier-depart...
where everything deploys great on tomcat but I can't make it work on Junit…

org.activiti.engine.ActivitiException: Unknown property used in expression: ${controleDossierService.controleDossier()}

Regards.

Edited : Finally, I made it work removing @RunWithJunit, @ApplicationContext, using ActivityRule and declaring the bean in activiti.cfg.xml

sagarsharma134
Champ in-the-making
Champ in-the-making
hello,
I was just wondering if there is  a way to just test a java service Task instead of deploying the whole bpm process through JUnit. My BPMN flow contains large number of service tasks and user tasks and I want to test these java service Tasks separately.  My service task follows the following signature:
public TaskProcessStatus processTask(DelegateExecution execution, String taskName, ServiceTask task){
//method body
}
I am not sure how do i populate the DelegateExecution execution in junit. I populated the map with my execution variables, how do i pass the map to the DelegateExecution .
I would appreciate the help.
Thank you

vasile_dirla
Star Contributor
Star Contributor
If you want to test just a single java delegate class, then you can create a simple process having only a ServiceTask using this delegate, when creating a process instance you can send the map of variables to be set on execution.

Like that:
<code>
    Map<String, Object> varMap = new HashMap<String, Object>();
    varMap.put("count", 0);
    varMap.put("count2", 0);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicServiceTask", varMap);

// getting a variable
runtimeService.getVariable(processInstance.getId(), "count");

setting a variable
runtimeService.setVariable(processInstance.getId(), "count" , 1);

setting multiple variables
runtimeService.setVariable(processInstance.getId(),  varMap);
</code>

Thank you vasile.dirla