Null reference exception thrown whilst trying to unit test simple workflow
Severity
P3 - Medium (Minor functionality affected)
Describe the Bug with repro steps
Expected
That I should be able to write a unit test for the workflow below mocking up the outputs of the service bus trigger and asserting that the inputs to the call workflow action are as expected and that I am passing the expected properties to the child workflow in the expected format
Actual
Unit test throws an unhandled error on the RunWorkflowAsync call. When I debug the unit test it is throwing an NRE inside GetTestWorkflowRun in Microsoft.Azure.Workflows.UnitTesting.TestHost. UnitTestEngine as run.Outputs is null.
It is unclear to me what the cause of this issue is and so how to work around it,
Steps to reproduce.
- Create unit tests in designer from workflow definition attached.
- In the test
xxx_ExecuteWorkflow_SUCCESS_Sample1mock up the trigger output as below
var triggerMockOutput = new WhenMessagesAreAvailableInATopicTriggerOutput
{
Body =
{
MessageId = "12345",
ContentData = new JObject {["Foo"] = "Bar"},
EnqueuedTimeUtc = "2025-10-24T15:53:40.083Z",
DeliveryCount = 1
}
};
In passing the choice of JObject for ContentData in the created Mocks doesn't look correct here as the content should just be a string but I don't think this is relevant to the behaviour being reported (I have tried changing datatype of that property and assigning a string with no effect)
- Run unit test. Unhandled error as below
System.NullReferenceException : Object reference not set to an instance of an object.
at Microsoft.Azure.Workflows.UnitTesting.TestHost.UnitTestEngine.ExecuteWorkflow(FlowPropertiesDefinition workflowDefinition, TriggerMock triggerMock, Dictionary`2 actionMocks, String appDirectory, String connections, String parameters, IDictionary`2 localSettings, String customCodeFunctionFilePath, Int32 timeoutInSeconds)
at Microsoft.Azure.Workflows.UnitTesting.TestHost.UnitTestEngine.ExecuteWorkflow(FlowPropertiesDefinition workflowDefinition, TriggerMock triggerMock, Dictionary`2 actionMocks, String appDirectory, String connections, String parameters, IDictionary`2 localSettings, String customCodeFunctionFilePath, Int32 timeoutInSeconds)
at Microsoft.Azure.Workflows.UnitTesting.UnitTestExecutor.RunWorkflowAsync(TestMockDefinition testMock, Int32 timeoutInSeconds)
What type of Logic App Is this happening in?
Standard (VSCode)
Are you experiencing a regression?
No response
Which operating system are you using?
Windows
Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg
Yes
Workflow JSON
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"actions": {
"Forward_to_POProcessing": {
"type": "Workflow",
"inputs": {
"host": {
"workflow": {
"id": "POProcessing"
}
},
"headers": {
"Content-Type": "application/json"
},
"body": {
"contentData": "@triggerBody()?['contentData']",
"messageId": "@triggerBody()?['messageId']",
"enqueuedTimeUtc": "@triggerBody()?['enqueuedTimeUtc']",
"deliveryCount": "@triggerBody()?['deliveryCount']"
},
"retryPolicy": {
"type": "none"
}
},
"runAfter": {}
}
},
"triggers": {
"When_messages_are_available_in_a_topic": {
"type": "ServiceProvider",
"description": "Receives Purchase Order messages from Service Bus and forwards to POProcessing workflow",
"inputs": {
"parameters": {
"topicName": "@appsetting('ServiceBusTopic')",
"subscriptionName": "@appsetting('ServiceBusSubscription')",
"isSessionsEnabled": false
},
"serviceProviderConfiguration": {
"connectionName": "serviceBus",
"operationId": "receiveTopicMessages",
"serviceProviderId": "/serviceProviders/serviceBus"
}
},
"splitOn": "@triggerOutputs()?['body']",
"splitOnConfiguration": {
"correlation": {
"clientTrackingId": "@triggerOutputs()?['body']?['messageId']"
}
}
}
}
},
"kind": "Stateful"
}
Screenshots or Videos
No response
Environment
As in previous reports
Additional context
No response
Hi @asos-martinsmith, the "Workflow" action type is required to be mocked in unit tests, and the child workflow should be tested separately. The null reference is unexpected though, you should be seeing the following error:
Can you confirm the version of the Microsoft.Azure.Workflows.Tests.Extension package in your .csproj file?