# Is there a way to start a unit test from the middle of the flow?

**URL:** <https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886>\
**Category:** Discussion & Questions\
**Tags:** process-engine\
**Created:** [August 12, 2020, 11:44pm UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886 "2020-08-12T23:44:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![devBunny](https://forum.camunda.io/letter_avatar_proxy/v4/letter/d/5f9b8f/32.png) [@devBunny](https://forum.camunda.io/u/devBunny)\
**Post date:** [August 12, 2020, 11:44pm UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886/1 "2020-08-12T23:44:09Z")

</div>

Hello community, I’m building some unit tests where my flow is something like A-B-C-D-E , but I would like to know if there’s a way to starting testing from C-D-E instead of A-B-C…

Thanks in advance

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [August 13, 2020, 3:15am UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886/2 "2020-08-13T03:15:09Z")

</div>

@devBunny, you can try something like below:

```auto
public void startAtSpecificActivity() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                                        .singleResult();

    runtimeService.createModification(processInstance.getId())
                               .startBeforeActivity("someServiceTask").execute();
}

```

To start after parallel gateway:

```auto
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
runtimeService.createProcessInstanceModification(processInstance.getId())  
  .startBeforeActivity("assessCreditWorthiness")
  .startBeforeActivity("registerApplication")
  .execute();

```

---

<div class="post-metadata">

**Author:** ![tmetzke](https://forum.camunda.io/user_avatar/forum.camunda.io/tmetzke/32/8631_2.png) [@tmetzke](https://forum.camunda.io/u/tmetzke)\
**Post date:** [August 13, 2020, 7:33am UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886/3 "2020-08-13T07:33:59Z")

</div>

Hey @devBunny,

maybe you want to have a look at our [Camunda BPM Assert examples](https://github.com/camundacon2019/process-testing) we showcased at CamundaCon 2019, it is specifically addressing those issues.

Feel free to watch the accompanying video as well:

[![](https://img.youtube.com/vi/gZF1kArXaa8/maxresdefault.jpg "Fluently test complex processes with BPM Assert - (CamundaCon 2019)") ](https://www.youtube.com/watch?v=gZF1kArXaa8)

Basically, what @aravindhrs proposes works fine. However, if you want to start your instance directly at a specific point instead of regularly starting it and then modifying it afterwards, you can use something like

```java
  @Test
  public void shouldDoWhateverYouSayItShould() {
    // given
    ProcessInstance instance = runtimeService()
        .createProcessInstanceByKey(PROCESS_KEY)
        .startBeforeActivity("C")
        .execute();
    // when
    ...
    // then
    assertThat(instance)
      .isActive()
      .isWaitingAt("D")
      ....;
  }

```

Hope that helps.

Best,  
Tobias

---

<div class="post-metadata">

**Author:** ![devBunny](https://forum.camunda.io/letter_avatar_proxy/v4/letter/d/5f9b8f/32.png) [@devBunny](https://forum.camunda.io/u/devBunny)\
**Post date:** [August 13, 2020, 1:48pm UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886/4 "2020-08-13T13:48:13Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![devBunny](https://forum.camunda.io/letter_avatar_proxy/v4/letter/d/5f9b8f/32.png) [@devBunny](https://forum.camunda.io/u/devBunny)\
**Post date:** [August 13, 2020, 1:48pm UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886/5 "2020-08-13T13:48:26Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 12:34pm UTC](https://forum.camunda.io/t/is-there-a-way-to-start-a-unit-test-from-the-middle-of-the-flow/21886/6 "2024-01-30T12:34:40Z")

</div>

Closed on January 30, 2024, 12:34pm UTC


