How to write a unit test for user assignee

Hi @rezza72,

from your other post it seems like BPM Assert is on your project’s path, so I’d recommend doing something like:

package com.example.test;

import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*;

import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.junit.Rule;
import org.junit.Test;

public class AssigneeTest {

  @Rule
  public ProcessEngineRule engineRule = new ProcessEngineRule(true);

  @Test
  @Deployment
  public void shouldAssignUser() {
    ProcessInstance processInstance = runtimeService().startProcessInstanceByKey(
        "process-definition-key", withVariables("user_id", "83282929"));
    assertThat(processInstance).task().isAssignedTo("83282929");
  }
}

No need to auto-wire the services yourself, no need to excessively use the low-level engine API in your tests.

Just make sure the model under test can be found at the location defined in the @Deployment annotation as documented.

Hope that helps.

Best,
Tobias

1 Like