sdk-java icon indicating copy to clipboard operation
sdk-java copied to clipboard

Provide way to populate activity execution context for activity unit tests

Open madhav2302 opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I am writing unit tests for activity with TestActivityEnvironment, and using var workflowType = Activity.getExecutionContext().getInfo().getWorkflowType(); in my activity.

There is no way to populate this execution context for as of now other then creating a temporary workflow using TestWorkflowEnvironment and creating a sample workflow.

Ideally, I should be able to setup execution context for tests without any interactions with workflows.

Describe the solution you'd like Something like below would be nice.

TestActivityEnvironment.newInstance(TestEnvironmentOptions.newBuilder().setActivityExecutionContext(...).build())

Describe alternatives you've considered Setting up test environment workflow, which is very tedious for unit tests.

Additional context See https://temporalio.slack.com/archives/CTT84KXK9/p1712848268603179

madhav2302 avatar Apr 11 '24 19:04 madhav2302

@mfateev @cretz are there any plans to work on this? it will help with making tests easier.

madhav2302 avatar Sep 20 '24 20:09 madhav2302

Hrmm, yes, it is common in other SDKs to be able to populate activity info for tests. So I believe that this will be done, but no concrete timeline currently. We will look to prioritize.

cretz avatar Sep 23 '24 12:09 cretz