---
title: Creating integration tests with a connection string
---

> 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).

Create integration tests if you need to access data from the Xperience database when writing [automated tests](https://docs.kentico.com/13/custom-development/writing-automated-tests.md). Note that integration tests are significantly slower than [unit tests with faked data](https://docs.kentico.com/13/custom-development/writing-automated-tests/faking-info-and-provider-objects-in-unit-tests.md).

All test classes with integration tests must inherit from the **IntegrationTests** base class (provided by the _CMS.Tests_ library). The base class ensures application initialization using a specific database connection string for each test.

## Creating integration tests

1. Open your solution in Visual Studio.
2. Create a **Tests.config** file in your [test project](https://docs.kentico.com/13/custom-development/writing-automated-tests/creating-automated-test-projects.md) (choose the _Application Configuration File_ template in the Add New Item dialog box).
3. Specify your testing database by adding the **CMSTestConnectionString** connection string to the _Tests.config_ file.

   ```xml

   <connectionStrings>
       <clear/>
       <add name="CMSTestConnectionString" connectionString="Persist Security Info=False;database=..."/>
   </connectionStrings>

   ```
4. Make the test class inherit from the **IntegrationTests** base class.

   ```csharp

   using CMS.Tests;
   using NUnit.Framework;

   [TestFixture]
   public class MyIntegrationTests : IntegrationTests
   {
       ...
   }

   ```
5. Write the required integration test methods.
6. (Optional) Add a method to the test class that cleans up all objects created or updated during the execution of tests.

   ```csharp

   [TearDown]
   public void MyIntegrationTestsCleanUp()
   {
       // Delete objects created during test execution
       ...

       // Return objects modified by tests to their previous state
       ...
   }

   ```

   > **Note:** **Note**: Each test class can have only one method marked with the **TearDown** attribute.

All tests in a test class inheriting from **IntegrationTests** use the database specified by the **CMSTestConnectionString** connection string. Changes made during tests that you do not clean up in the tear down method remain in the database after the test runs finish.

**Important**: Use [isolated integration](https://docs.kentico.com/13/custom-development/writing-automated-tests/creating-isolated-integration-tests.md) tests if you cannot reset data modified during test execution back to its previous state (to avoid affecting other tests).
