Support for writing Isolated tests for Xperience Mvc applications, based on the Microsoft.AspNetCore.Mvc.Testing & Kentico.Xperience.Libraries.Tests frameworks.
For more information on Mvc Integration testing and automated testing in Kentico, see:
- Install the package into your Xperience Mvc Test project:
Kentico versions
<13.0.19
are not supported when targetingnet5.0
, due to a bug withinKentico.Xperience.Libraries.Tests
.
dotnet add package BizStream.Kentico.Xperience.AspNetCore.Mvc.Testing
OR
<PackageReference Include="BizStream.Kentico.Xperience.AspNetCore.Mvc.Testing" Version="x.x.x" />
- Implement a
TestFixture
derived fromAutomatedTestWithIsolatedWebApplication<TStartup>
:
[TestFixture( Category = "IsolatedMvc" )]
public class ExampleIsolatedWebTests : AutomatedTestWithIsolatedWebApplication<ExampleApp.Startup>
{
[Test]
public async Task Get_Root_ShouldReturnSuccessAndContent( )
{
var response = await Client.GetAsync( "/" );
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
Assert.IsFalse( string.IsNullOrWhiteSpace( content ) );
}
}