---
title: Creating automated test projects
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Automated tests often mirror the structure of the tested code. For example, we recommend creating at least one test project for every custom project that you have in your Kentico solution. You can have any number of test projects in the solution.

The following steps describe how to create test projects using the Kentico **CMS.Tests** library, based on either [NUnit](http://www.nunit.org/) or the Microsoft unit test framework.

### NUnit

1. Install the [**NUnit Test Adapter**](https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d) Visual Studio extension.
2. Open your Kentico solution in Visual Studio (using the **WebSite.sln** or **WebApp.sln** file).
3. Add a new project to the solution using the **Class Library** project template.
   - **Important**: The name of the project must end with the **.Tests** suffix.
4. Add references to the following libraries located in the Kentico solution's **Lib** directory:

   - **CMS.Base.dll**
   - **CMS.DataEngine.dll**
   - **CMS.Tests.dll**
   - **nunit.framework.dll**
5. Add references to the project containing the code that you wish to test and any other required projects.

### Microsoft unit test framework

1. Open your Kentico solution in Visual Studio (using the **WebSite.sln** or **WebApp.sln** file).
2. Add a new project to the solution using **Unit Test Project** template (in the New Project dialog box, expand the **Installed** node, choose the language that you want to use for your test project, and then choose **Test**).
   - **Important**: The name of the project must end with the **.Tests** suffix.
3. Add references to the following libraries located in the Kentico project's **Lib** directory:

   - **CMS.Base.dll**
   - **CMS.DataEngine.dll**
   - **CMS.Tests.dll**
4. Add references to the project containing the code that you wish to test and all other required projects.

Now you can write test classes inside the new test project. You can use the Visual Studio Test Explorer to execute your tests.

```csharp title="NUnit test class example"

using CMS.Tests;
using NUnit.Framework;

namespace UnitTestExample
{
    [TestFixture]
    public class MyTests : UnitTests
    {
        [SetUp]
        public void MyTestSetUp()
        {
            // Setup executed before each test in this test class
        }

        [Test]
        public void MyTest()
        {
            // Test execution
        }
    }
}

```

For additional information about writing tests, see the following pages:

- [Faking Info and Provider objects in unit tests](https://docs.kentico.com/k9/custom-development/writing-automated-tests/faking-info-and-provider-objects-in-unit-tests.md)
- [Creating integration tests with a connection string](https://docs.kentico.com/k9/custom-development/writing-automated-tests/creating-integration-tests-with-a-connection-string.md)
- [Creating isolated integration tests](https://docs.kentico.com/k9/custom-development/writing-automated-tests/creating-isolated-integration-tests.md)
