Creating automated test projects
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 Xperience solution. You can have any number of test projects in the solution.
The following steps describe how to create test projects using the Xperience CMS.Tests library:
Open your Xperience solution in Visual Studio.
Add a new project to the solution and select the Class Library project template.
- Important: The name of the project must end with the .Tests suffix.
Right-click the test project in the Solution Explorer and select Manage NuGet Packages.
Search for the Kentico.Xperience.Libraries.Tests package.
Install the Kentico.Xperience.Libraries.Tests version that matches the hotfix version of your Xperience instance (with all dependencies).
Maintaining Kentico.Xperience.Libraries.Tests
If you upgrade or hotfix the related Xperience project to a newer version, you also need to update the Kentico.Xperience.Libraries.Tests NuGet package to a matching version in your test projects.
We also recommend installing theĀ NUnit3TestAdapter NuGet package. The package is required to run NUnit tests.
- Alternatively, you can install the NUnit 3 Test Adapter Visual Studio extension.
Add references from the test project to all projects whose code you wish to test, and any other required project.
Rebuild the solution.
Now you can write test classes inside the new test project. You can use the Visual Studio Test Explorer to execute your tests.
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: