cancel
Showing results for 
Search instead for 
Did you mean: 

How to Unit test Service Task

rajeshwaranmsc
Champ in-the-making
Champ in-the-making
Hi,

I am new to Activiti. I wondering is there a way to write unit test on different task level.
I am using web service delegate for our service task and I can do a integration test provided my web services are deployed.

Please any one can guide me in writing a unit test to test the service test somthing like mocking the web service so that dont have to call the web service.


regards
Rajesh
1 REPLY 1

jbarrez
Star Contributor
Star Contributor
Are you using the latest version of Activiti?
There is an undocumented feature that allows you to mock out service tasks, for example:

<code>
@Test
@Deployment(resources = {"org/activiti/standalone/testing/MockSupportWithActivitiRuleTest.testMockedServiceTaskAnnotation.bpmn20.xml"})
@MockServiceTask(id = "serviceTask", mockedClassName="org.activiti.standalone.testing.helpers.ServiceTaskTestMock")
public void testMockedServiceTaskByIdAnnotation() {
  Assert.assertEquals(0, ServiceTaskTestMock.CALL_COUNT.get());
  activitiRule.getRuntimeService().startProcessInstanceByKey("mockSupportTest");
  Assert.assertEquals(1, ServiceTaskTestMock.CALL_COUNT.get());
}

@Test
@Deployment
@MockServiceTasks({
   @MockServiceTask(originalClassName="com.yourcompany.delegate1", mockedClassName="org.activiti.standalone.testing.helpers.ServiceTaskTestMock"),
   @MockServiceTask(originalClassName="com.yourcompany.delegate2", mockedClassName="org.activiti.standalone.testing.helpers.ServiceTaskTestMock")
})
public void testMockedServiceTasksAnnotation() {
  Assert.assertEquals(0, ServiceTaskTestMock.CALL_COUNT.get());
  activitiRule.getRuntimeService().startProcessInstanceByKey("mockSupportTest");
  Assert.assertEquals(2, ServiceTaskTestMock.CALL_COUNT.get());
}

</code>