At present time, an activity function must take in as a parameter a DurableActivityContext which is not an abstract class or an interface. This makes it difficult to create unit tests for activity functions because input needs to be passed in through context.GetInput<T>().
This is true, but it generally shouldn't be needed. See our unit test documentation here: https://docs.microsoft.com/en-us/azure/azure-functions/durable-functions-unit-testing#unit-testing-activity-functions
Activity functions can be unit tested in the same way as non-durable functions. Activity functions don't have a base class for mocking. So the unit tests use the parameter types directly.
In other words, it's not necessary to use DurableActivityContext as your parameter type. You can use T directly as the parameter type.
@cgillum There are still cases where this is important. I have an app relying on a consistent instance id to correlate logs from orchestrator and activity functions. Taking DurableActivityContext as the ActivityTrigger parameter simplifies getting both instance id and input data to the activity function, but without a mockable DurableActivityContext testing the activity is painful.
@chlowell Fair enough. I'll reopen to track adding this.
This work has been merged - we now have a DurableActivityContextBase class, which can be mocked! It will be available in the next release (v1.7.0).
Most helpful comment
This work has been merged - we now have a
DurableActivityContextBaseclass, which can be mocked! It will be available in the next release (v1.7.0).