Create integration tests

Overview

Writing integration tests in Sitefinity CMS using MSTest V2 framework appears to be very similar to writing MSTest unit tests. The integration tests are structured in test classes. Each test class holds a set of tests, setup logic, and cleanup logic. For more information about each element, refer to the sections below.

Test classes

The test classes hold the tests. You can use multiple test classes and group your tests depending on the functionality they cover. Each test class is represented by a class. To create a test class, perform the following:

  1. Create an empty class file that inherits from SitefinityIntegrationTestsBase class.
  2. Mark the class with the the TestClass attribute (required).
    Note that the class must be public.

Tests

The tests are represented by methods, which contain the logic that you want to test. To create a test method, perform the following:

  1. Create a void method which does not accept any arguments.
  2. Mark the method with the SitefinityIntegrationTest attribute (required).
  3. Mark the method with optional attributes:
    • TestCategory - the attribute may be applied on class or method level. All Sitefinity integration tests must have a category to be included in the CI test execution.
    • Owner - the attribute may be applied on method level only.
    • Description - the attribute may be applied on method level only.
    • Ignore - if specified, the test will be ignored.
    • ExpectedException - expects specific exception type to be thrown.
  4. Write the logic that you want to test.
  5. Assert the results.

Setup logic and cleanup logic

Note that the attributes for setup logic and cleanup logic are handled from the base class SitefinityIntegrationTestsBase. Therefore, if you implement some common setup and cleanup logic, you need to override the following methods:

  • ClassInitialize()
    Note that this method must have access to static variables only. The method is executed once before all tests in the test class.
  • ClassCleanup()
    Note that this method must have access to static variables only. The method is executed once before all tests in the test class. Executes always, even on test or setup failures.
  • TestInitialize()
    This method is executed before each test. 
  • TestCleanup()
    This method is executed after each test. Executes always, even on test or setup failures. 

Integration tests sample

Below is an integration tests example using MSTest V2 framework:

For more information, see the Integration Tests Sample on Sitefinity GitHub repository.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?