Hello!
I have a parent workflow inside of which I am spawning a child workflow implementation of which is present in a different service(I have access only to child workflow’s interface)
So I need to write integration test where parent workflow is triggered from the temporal test env (I am aware that for this we can use TestWorkflowRule, TestWorkflowExtension, or using manual TestWorkflowEnvironment setup) and directly mock the result of child workflow (I dont want to trigger child workflow in test env, just need to mock the result).
I have tried many most of the things mentioned above i.e. TestWorkflowExtension, TestWorkflowEnvironment but none of it seems to work. Even after mocking the child workflow response, it still tries to trigger the child workflow instead of directly returning me the mocked response.
Below is the snippet of what I have tried :
@RegisterExtension
public final TestWorkflowExtension testWorkflowExtension =
TestWorkflowExtension.newBuilder()
.setWorkflowTypes(ParentWorkflowImpl.class)
.setDoNotStart(true)
.setActivityImplementations(new SampleActivityImpl(d1, d2, d3, d4))
.build();
// mocking the child workflow response : here ChildWorkflow is an interface of child workflow
worker.addWorkflowImplementationFactory(
ChildWorkflow.class,
() -> {
ChildWorkflow child = mock(ChildWorkflow.class);
when(child.triggerWorkflow(any())).thenReturn(mockResponse);
lastChildMock.set(child);
return child;
});
Please help with this, thank you!