camunda BPM community extension providing support for the Needle testing framework
Switch branches/tags
Nothing to show
Clone or download


Maven Central

Needle4j (f.k.a. needle) is a framework to ease DI testing. It allows writing very effective, boilerplate free Junit or TestNG test by providing mocks for every Injection point.

needle4j logo

This is how a test written with needle looks like. Check out the source code for the full example.

 public static final String USER_ID = "foo";

  public final NeedleRule needleRule = needleRule().build();

  @ObjectUnderTest(implementation = TestProcessStarterBean.class)
  private TestProcessStarter testProcessStarter;

  private RuntimeService runtimeService;

  public void should_start_process_with_userId() {
    final String businessKey = UUID.randomUUID().toString();

    testProcessStarter.startProcessWithUser(USER_ID, businessKey);

            businessKey, variablesStartedByUser(USER_ID));

Now, this is the bean test. Now you want to write the process test. Since you have special requirements how the process is started and you already tested the behavior, instead of rewriting the process start manually, why not reuse the process starter.

This is where camunda-bpm-needle gets useful. Instead of using mocks (like in the previous sample), the ProcessEngineNeedleRule can inject the in memory process engine services into your test case and use your beans. And since you are still working with the in memory engine, you can easily use mocks for the parts of the process you do not want (or need) to test here.

  public final ProcessEngineNeedleRule processEngineNeedleRule = ProcessEngineNeedleRule.fluentNeedleRule(this).build();

  @ObjectUnderTest(implementation = TestProcessStarterBean.class)
  public TestProcessStarter testProcessStarter;

  private JavaDelegate serviceTaskMock;

  private TaskService taskService;

  private RuntimeService runtimeService;

  @Deployment(resources = "test-process.bpmn")
  public void should_deploy_and_start_process_via_starter_bean() {
    Mocks.register("serviceTask", serviceTaskMock);

    final ProcessInstance processInstance = testProcessStarter.startProcessWithUser("foo", UUID.randomUUID().toString());


    Task task = taskService.createTaskQuery().active().singleResult();



Get started

Just include camunda-bpm-needle in the test scope of your project:


and start using NeedleRule or ProcessEngineNeedleRule in your tests. Have a look at the examples in (src/test/java).




Apache License, Version 2.0