# Testing Activities

**URL:** <https://community.temporal.io/t/testing-activities/1403>\
**Category:** Community Support\
**Tags:** go-sdk\
**Created:** [January 28, 2021, 8:42pm UTC](https://community.temporal.io/t/testing-activities/1403 "2021-01-28T20:42:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![marimp8888](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/marimp8888/32/956_2.png) [@marimp8888](https://community.temporal.io/u/marimp8888)\
**Post date:** [January 28, 2021, 8:42pm UTC](https://community.temporal.io/t/testing-activities/1403/1 "2021-01-28T20:42:03Z")

</div>

Hi guys,  
I’m trying to use a test suite for verifying the workflows and activities input and output. Regarding Activities I was able to verify inputs by using method env.onActivity but I was not able to test output. Is it possible to call an activity, really execute it and test the related result? I did not find an example in the go ask sample repository regarding this.  
Could you suggest me an approach?

Great thanks for your time  
Marco

---

<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:** [January 28, 2021, 8:53pm UTC](https://community.temporal.io/t/testing-activities/1403/2 "2021-01-28T20:53:18Z")

</div>

Use [TestActivityEnvironment](https://github.com/temporalio/sdk-go/blob/d843b784901c70fbcd4404aecda5f953725e0f19/testsuite/testsuite.go#L40) for activity testing. It is created through `WorkflowTestSuite.NewActivityEnvironment`.

---

<div class="post-metadata">

**Author:** ![marimp8888](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/marimp8888/32/956_2.png) [@marimp8888](https://community.temporal.io/u/marimp8888)\
**Post date:** [January 29, 2021, 9:43pm UTC](https://community.temporal.io/t/testing-activities/1403/3 "2021-01-29T21:43:27Z")

</div>

Great thanks Maxim,  
I successfully used the suggested method and all works fine.  
A last question about the topic: could you confirm that the test suite requires the temporal server up and running and that there is no possibility to test and mock without it?  
Thanks in advance.  
Marco

---

<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:** [January 30, 2021, 12:19am UTC](https://community.temporal.io/t/testing-activities/1403/4 "2021-01-30T00:19:28Z")

</div>

> could you confirm that the test suite requires the temporal server up and running and that there is no possibility to test and mock without it?

Not confirming.

The unit testing framework does not need the temporal service up and running.

---

<div class="post-metadata">

**Author:** ![marimp8888](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/marimp8888/32/956_2.png) [@marimp8888](https://community.temporal.io/u/marimp8888)\
**Post date:** [February 1, 2021, 6:11pm UTC](https://community.temporal.io/t/testing-activities/1403/5 "2021-02-01T18:11:28Z")

</div>

It was my fault. I wrongly run the worker during test. I adjusted code and all works fine.

Thanks again for your support  
Regards  
Marco

---

<div class="post-metadata">

**Author:** ![DHRUVIL\_PATEL](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/dhruvil_patel/32/1414_2.png) [@DHRUVIL\_PATEL](https://community.temporal.io/u/DHRUVIL_PATEL)\
**Post date:** [February 18, 2022, 8:56am UTC](https://community.temporal.io/t/testing-activities/1403/6 "2022-02-18T08:56:43Z")

</div>

Hi @maxim, I am trying to test workflow using testsuite.TestWorkflowEnvironment.

I am able to test activities for errors using OnActivity().Return() by returning errors. But when i use the similar OnActivity().Return() for response with nil error, i am not able to see the value from response in the actual workflow.

sample activity call in workflow :

```auto
var response string
err = workflow.ExecuteActivity(ctx, SampleActivity).Get(ctx, &response)
if err != nil {
	workflow.GetLogger(ctx).Error("SampleActivity failed with ", err)
	return err
}

```

Mocking used in unit test :

```auto
s.env.OnActivity(SampleActivity, mock.Anything).Return(func(ctx context.Context) (string, error) {
		return "test_string", nil
})

```

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [February 18, 2022, 4:43pm UTC](https://community.temporal.io/t/testing-activities/1403/7 "2022-02-18T16:43:12Z")

</div>

> i am not able to see the value from response in the actual workflow.

Can you clarify this? What is `response` after ExecuteActivity is invoked there or otherwise what error is happening during run? Also, you don’t have to do a callback, `.Return("test_string", nil)` should be acceptable.

(if easier, you might want to make a new forum post instead of reusing this older one)

---

<div class="post-metadata">

**Author:** ![DHRUVIL\_PATEL](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/dhruvil_patel/32/1414_2.png) [@DHRUVIL\_PATEL](https://community.temporal.io/u/DHRUVIL_PATEL)\
**Post date:** [February 18, 2022, 5:36pm UTC](https://community.temporal.io/t/testing-activities/1403/8 "2022-02-18T17:36:13Z")

</div>

Create new [post](https://community.temporal.io/t/activity-response-does-not-return-correct-value-on-call-to-onactivity-return/4033)
