# Unit tests for Workflow in Springboot

**URL:** <https://community.temporal.io/t/unit-tests-for-workflow-in-springboot/10144>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [November 18, 2023, 4:59pm UTC](https://community.temporal.io/t/unit-tests-for-workflow-in-springboot/10144 "2023-11-18T16:59:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebin](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@sebin](https://community.temporal.io/u/sebin)\
**Post date:** [November 18, 2023, 4:59pm UTC](https://community.temporal.io/t/unit-tests-for-workflow-in-springboot/10144/1 "2023-11-18T16:59:23Z")

</div>

I am writing unit tests for a workflow using the annotation @RegisterExtension that injects the desired workflow implementation.

My workflow invokes multiple activity methods of a certain MyActivityImpl.class  
I have added the following  
@InjectMocks  
MyActivityImpl activity

However the following  
when(activity.someMethod).thenReturn(someResult)  
instead of returning someResult always tries to execute the implementation of someMethod

The links to java testing samples is broken. And upon visiting the working link, I found the test cases to be too trivial.  
Are there better practical testing samples? Are there samples that use junit5?  
Like testing a workflow with few activities in it and how to mock those activities as the above straightforward approach doesn’t seem to be working

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 18, 2023, 5:54pm UTC](https://community.temporal.io/t/unit-tests-for-workflow-in-springboot/10144/2 "2023-11-18T17:54:22Z")

</div>

Use TestWorkflowRule or TestWorkflowEnvironment to test workflows.

Here are some samples:

> <https://github.com/temporalio/samples-java/blob/main/core/src/test/java/io/temporal/samples/moneytransfer/TransferWorkflowTest.java>

> <https://github.com/temporalio/samples-java/blob/main/core/src/test/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalInterceptorTest.java>

See more at [https://github.com/temporalio/samples-java/tree/main/core/src/test/java/io/temporal/samples](https://github.com/temporalio/samples-java/tree/main/core/src/test/java/io/temporal/samples)

---

<div class="post-metadata">

**Author:** ![sebin](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@sebin](https://community.temporal.io/u/sebin)\
**Post date:** [November 19, 2023, 6:55am UTC](https://community.temporal.io/t/unit-tests-for-workflow-in-springboot/10144/3 "2023-11-19T06:55:25Z")

</div>

Thank you maxim. The link helped.  
The example that helped me is

> <https://github.com/temporalio/samples-java/blob/main/core/src/test/java/io/temporal/samples/hello/HelloActivityJUnit5Test.java>

as I planned to use junit5

It would be great if this was linked under junit5 testing in the documentation, as the documentation missed out the important part of the code  
**// withoutAnnotations() is required to stop Mockito from copying**  
\*\* // method-level annotations from the GreetingActivities interface\*\*  
GreetingActivities activities =  
mock(GreetingActivities.class, withSettings().withoutAnnotations());
