Skip to content

Test Infrastructure

This document and examples will be base on following tooling.

  • xUnit as the test framework.
  • NSubstitute as the mocking library.
  • Shouldly as the assertion library.
  • dotnet test as the gitlab ci/cd template for running unit tests.

  • Do define test.props file that can be shared across multiple projects within a solution.

<Project> 
  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="X.Y.Z">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="JunitXml.TestLogger" Version="X.Y.Z" />
  </ItemGroup> 
</Project>

In this case, the test.props file is defining two PackageReference elements, which are used to reference NuGet packages for test-related purposes:

  1. coverlet.collector (version X.Y.Z) - A code coverage analysis tool for .NET applications. It collects code coverage data during testing and generates coverage reports.

  2. JunitXml.TestLogger (version X.Y.Z) - A test logger for .NET applications that generates JUnit-style XML test result files. This can be useful for reporting test results to systems that expect JUnit-style XML output, such as Jenkins or other continuous integration tools.

Replace version number with latest available.

The test.props file can be imported into the *.csproj file as shown below.

<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="..\..\common.props" />
  <Import Project="..\test.props" />
  ...
</Project>
  • Do import test.props following unit test projects.
    • GridLab.PSSX.<ModuleName>.Application.Tests
    • GridLab.PSSX.<ModuleName>.Domain.Tests
    • GridLab.PSSX.<ModuleName>.EntityFrameworkCore.Tests