Azure / Azure/LogicAppsUX

Null reference exception thrown whilst trying to unit test simple workflow

Open
#8,457 2 comments 0 reactions 1 assignee Claimed by @andrew-eldridge View on GitHub
bug needs-investigation VSCode
Dominant language
TypeScript
Stars
111
Forks
109
Avg merge
1d 23h
Merged PRs (30d)
20

Description

### 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_Sample1` mock 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

```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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.