---
title: "Unit Testing Pulumi programs in C#"
description: "An example that applies unit testing to C# and Azure resources."
url: "https://www.pulumi.com/dev/examples/testing-unit-cs-mocks/"
image: "https://www.pulumi.com/assets/og/dev/examples/testing-unit-cs-mocks.png"
---

# Unit Testing Pulumi programs in C#

An example that applies unit testing to C# and Azure resources.

- Source on GitHub: https://github.com/pulumi/examples/tree/master/testing-unit-cs-mocks

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/testing-unit-cs-mocks) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set testing-unit-cs-mocks
cd pulumi-examples/testing-unit-cs-mocks
```

An example of writing mock-based unit tests with both infrastructure definition and tests written in C#.
The example uses the [NUnit](https://nunit.org/) test framework to define and run the tests and [FluentAssertions](https://github.com/fluentassertions/fluentassertions) for assertions.

It defines a stack that deploys a static website to Azure Storage and a suite of tests to validate the deployment. It also shows several examples of changing mocks for the testing needs, including mocking an `Invoke` (data source) call - `ListStorageAccountKeys` - whose result contains a nested array of complex objects.

## Prerequisites

[Install .NET Core 3.1+](https://dotnet.microsoft.com/download)

## Running the tests

Run the tests:

```bash
$ dotnet test

Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 6 test files matched the specified pattern.

Test Run Successful.
Total tests: 6
     Passed: 6
 Total time: 1.2167 Seconds
```

## Further steps

Learn more about testing Pulumi programs:

- [Testing Guide](https://www.pulumi.com/docs/guides/testing/)
- [Unit Testing Guide](https://www.pulumi.com/docs/guides/testing/unit/)
