# Mock child workflows

**URL:** <https://community.temporal.io/t/mock-child-workflows/8978>\
**Category:** Community Support\
**Tags:** go-sdk\
**Created:** [July 27, 2023, 5:09pm UTC](https://community.temporal.io/t/mock-child-workflows/8978 "2023-07-27T17:09:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![meg](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@meg](https://community.temporal.io/u/meg)\
**Post date:** [July 27, 2023, 5:09pm UTC](https://community.temporal.io/t/mock-child-workflows/8978/1 "2023-07-27T17:09:52Z")

</div>

Hi,  
I have a use case where from my workflow (MyWorkFlow), I execute a child workflow in another service.  
Now, I am writing a unit test for MyWorkFlow and have to mock this child workflow. I am not sure how to register this workflow in the test env. This is what I tried-

1. Register workflow with test workflow environment  
s.env.RegisterWorkflow(“ChildWFInAnotherService”)

2. Mock the response  
s.env.OnWorkflow(“ChildWFInAnotherService”, mock.Anything).Return(mockResponse).  
This throws an error on Register -  
**test panicked: expected a func as input but was string**  
I think I need to give the child workflow name as a function reference, but not sure how if its on another service. Any suggestions?

Thanks

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [July 27, 2023, 10:15pm UTC](https://community.temporal.io/t/mock-child-workflows/8978/2 "2023-07-27T22:15:48Z")

</div>

Hello @meg

I think this example is doing something similar,

> <https://github.com/temporalio/samples-go/blob/5226001f47962e3779d2e0c122b965a9a817cfb8/child-workflow/parent_workflow_test.go#L32C18-L32C37>

Let me know if it helps,

Antonio

---

<div class="post-metadata">

**Author:** ![meg](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@meg](https://community.temporal.io/u/meg)\
**Post date:** [July 27, 2023, 10:47pm UTC](https://community.temporal.io/t/mock-child-workflows/8978/3 "2023-07-27T22:47:51Z")

</div>

Thanks for you reply @antonio.perez .  
If you see my example, this is what I tried. But since the child workflow belongs to a different service, and hence not in this repository, it doesn’t recognize it.  
In the sample code, the child workflow code is available.

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [July 27, 2023, 11:17pm UTC](https://community.temporal.io/t/mock-child-workflows/8978/4 "2023-07-27T23:17:55Z")

</div>

Hi @meg

sorry,

I guess you have to provide an implementation to the RegisterWorkflow method. It can be an empty one with the same signature.

Let me ask the team and see if there are other options.

Antonio

---

<div class="post-metadata">

**Author:** ![meg](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@meg](https://community.temporal.io/u/meg)\
**Post date:** [July 31, 2023, 7:41am UTC](https://community.temporal.io/t/mock-child-workflows/8978/5 "2023-07-31T07:41:50Z")

</div>

Hi @antonio.perez ,

Not sure I understand. Can you please elaborate?

Thanks!

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [July 31, 2023, 9:18am UTC](https://community.temporal.io/t/mock-child-workflows/8978/6 "2023-07-31T09:18:02Z")

</div>

@meg

in your test, you can declare the following function

```auto
func SampleChildWorkflow(ctx workflow.Context, name string) (string, error) {
return "greeting", nil
}

```

and register it as follows

```auto
	env.RegisterWorkflow(SampleChildWorkflow)
	env.OnWorkflow("SampleChildWorkflow", mock.Anything, mock.Anything).Return(
		func(ctx workflow.Context, name string) (string, error) {
			return "Hi " + name + "!", nil
		},
	)

```

Antonio
