# TestWorkflowExtension fails workflow when Workflow.sleep(duration)

**URL:** <https://community.temporal.io/t/testworkflowextension-fails-workflow-when-workflow-sleep-duration/7685>\
**Category:** Community Support\
**Tags:** java-sdk, testing\
**Created:** [March 25, 2023, 12:14am UTC](https://community.temporal.io/t/testworkflowextension-fails-workflow-when-workflow-sleep-duration/7685 "2023-03-25T00:14:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theresa\_Chen](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/theresa_chen/32/2761_2.png) [@Theresa\_Chen](https://community.temporal.io/u/Theresa_Chen)\
**Post date:** [March 25, 2023, 12:14am UTC](https://community.temporal.io/t/testworkflowextension-fails-workflow-when-workflow-sleep-duration/7685/1 "2023-03-25T00:14:37Z")

</div>

Hello. I am using TestWorkflowExtension to run tests for my workflow.

Here is how I initialized TestWorkflowExtension

```auto
    public static final TestWorkflowExtension testWorkflowExtension =
            TestWorkflowExtension.newBuilder()
                    .setWorkflowTypes(MyWorkflowImpl.class)
                    .setDoNotStart(true)
                    .build();

```

Inside the workflow’s execute(), I have a `Workflow.sleep(duration)` where the duration positive. However, when this line is called, an InvocationTargetException is thrown. How can I avoid this exception?

---

<div class="post-metadata">

**Author:** ![taonic](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/taonic/32/5556_2.png) [@taonic](https://community.temporal.io/u/taonic)\
**Post date:** [March 25, 2023, 9:23am UTC](https://community.temporal.io/t/testworkflowextension-fails-workflow-when-workflow-sleep-duration/7685/2 "2023-03-25T09:23:57Z")

</div>

Hey @Theresa_Chen do you mind to share the stack trace?
