@@ -23,6 +23,7 @@ package internal
2323
2424import (
2525 "context"
26+ "github.com/stretchr/testify/mock"
2627 "github.com/stretchr/testify/suite"
2728 "strings"
2829 "testing"
@@ -129,6 +130,53 @@ func TestWorkflowReturnNil(t *testing.T) {
129130 require .NoError (t , err )
130131}
131132
133+ func HelloWorkflow (ctx Context , name string ) (string , error ) {
134+ ctx = WithActivityOptions (ctx , ActivityOptions {
135+ ScheduleToCloseTimeout : time .Hour ,
136+ StartToCloseTimeout : time .Hour ,
137+ ScheduleToStartTimeout : time .Hour ,
138+ })
139+ var result string
140+ err := ExecuteActivity (ctx , HelloActivity , name ).Get (ctx , & result )
141+ return result , err
142+ }
143+
144+ func HelloActivity (ctx context.Context , name string ) (string , error ) {
145+ return "Hello " + name + "!" , nil
146+ }
147+
148+ func TestWorkflowMockingWithoutRegistration (t * testing.T ) {
149+ testSuite := & WorkflowTestSuite {}
150+ env := testSuite .NewTestWorkflowEnvironment ()
151+ env .OnWorkflow (HelloWorkflow , mock .Anything , mock .Anything ).Return (
152+ func (ctx Context , person string ) (string , error ) {
153+ return "Hello " + person + "!" , nil
154+ })
155+ // Workflow is mocked, no activity registration required
156+ env .ExecuteWorkflow (HelloWorkflow , "Cadence" )
157+ require .NoError (t , env .GetWorkflowError ())
158+ var result string
159+ err := env .GetWorkflowResult (& result )
160+ require .NoError (t , err )
161+ require .Equal (t , "Hello Cadence!" , result )
162+ }
163+
164+ func TestActivityMockingWithoutRegistration (t * testing.T ) {
165+ testSuite := & WorkflowTestSuite {}
166+ env := testSuite .NewTestWorkflowEnvironment ()
167+ env .OnActivity (HelloActivity , mock .Anything , mock .Anything ).Return (
168+ func (ctx context.Context , person string ) (string , error ) {
169+ return "Goodbye " + person + "!" , nil
170+ })
171+ // Registration of activity not required
172+ env .RegisterWorkflow (HelloWorkflow )
173+ env .ExecuteWorkflow (HelloWorkflow , "Cadence" )
174+ require .NoError (t , env .GetWorkflowError ())
175+ var result string
176+ err := env .GetWorkflowResult (& result )
177+ require .NoError (t , err )
178+ require .Equal (t , "Goodbye Cadence!" , result )
179+
132180type InterceptorTestSuite struct {
133181 suite.Suite
134182 WorkflowTestSuite
0 commit comments