Creating integration tests with a connection string

Create integration tests if you need to access data from the Xperience database when writing automated tests. Note that integration tests are significantly slower than unit tests with faked data.

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

    
    
    
     <connectionStrings>
         <clear/>
         <add name="CMSTestConnectionString" connectionString="Persist Security Info=False;database=..."/>
     </connectionStrings>
    
    
     
  4. Make the test class inherit from the IntegrationTests base class.

    
    
    
     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.

    
    
    
     [TearDown]
     public void MyIntegrationTestsCleanUp()
     {
         // Delete objects created during test execution
         ...
    
         // Return objects modified by tests to their previous state
         ...
     }
    
    
     

    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 tests if you cannot reset data modified during test execution back to its previous state (to avoid affecting other tests).