Table of Contents

Interface IDotnetTestHelper

Namespace
Invex.Atom.Module.Dotnet.Helpers
Assembly
Invex.Atom.Module.Dotnet.dll

Provides helper methods for running .NET tests and staging their results and code coverage reports.

public interface IDotnetTestHelper : IDotnetCliHelper, IBuildInfo, IDotnetToolInstallHelper, IReportsHelper, IBuildAccessor
Inherited Members

Remarks

This interface extends IDotnetCliHelper for executing dotnet test commands, IBuildInfo for build version information, IDotnetToolInstallHelper for installing necessary tools, and IReportsHelper for generating build reports.

Methods

DotnetTestAndStage(RootedPath, DotnetTestAndStageOptions?, CancellationToken)

Runs tests for a .NET project specified by its path, then stages the test results and optionally code coverage reports.

Task<int> DotnetTestAndStage(RootedPath projectPath, DotnetTestAndStageOptions? options = null, CancellationToken cancellationToken = default)

Parameters

projectPath RootedPath

The full path to the project file (e.g., "tests/MyProject.Tests/MyProject.Tests.csproj").

options DotnetTestAndStageOptions

Optional. Configuration options for the testing and staging process.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<int>

A System.Threading.Tasks.Task<TResult> that returns the exit code of the dotnet test command.

Remarks

This method performs the following steps:

  1. Configures `dotnet test` options, including TRX and HTML loggers, and optionally code coverage.
  2. Cleans up existing test result directories.
  3. Applies version transformations to project files if SetVersionsFromProviders is true.
  4. Executes the `dotnet test` command using Test(RootedPath, DotnetTestOptions?, ProcessRunOptions?, CancellationToken).
  5. Copies the generated HTML test report to the Atom publish directory.
  6. Generates a detailed test report using GenerateTestReport(string, string?, string?, string, bool).
  7. If IncludeCoverage is true, installs `dotnet-reportgenerator-globaltool` and generates code coverage reports.
  8. Generates a code coverage report using GenerateCoverageReport(string, string?, string?, string, bool).

The BuildVersion is used for version transformation.

Exceptions

StepFailedException

Thrown when the dotnet test invocation fails before producing any test results (e.g. a build error, invalid arguments, or a crashed test host), as opposed to the run completing with failing tests. This is detected by the absence of a TRX results file on a non-zero exit code. Failing tests do not throw and instead surface via the returned exit code and the generated test report.

DotnetTestAndStage(string, DotnetTestAndStageOptions?, CancellationToken)

Runs tests for a .NET project by its name, then stages the test results and optionally code coverage reports.

Task<int> DotnetTestAndStage(string projectName, DotnetTestAndStageOptions? options = null, CancellationToken cancellationToken = default)

Parameters

projectName string

The name of the project to test (e.g., "MyProject.Tests").

options DotnetTestAndStageOptions

Optional. Configuration options for the testing and staging process.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task<int>

A System.Threading.Tasks.Task<TResult> that returns the exit code of the dotnet test command.

Remarks

This method first locates the project file based on its name, then calls DotnetTestAndStage(RootedPath, DotnetTestAndStageOptions?, CancellationToken) with the resolved path.

Exceptions

StepFailedException

Thrown if the project file cannot be located.

GenerateCoverageReport(string, string?, string?, string, bool)

Generates a code coverage report from a JSON summary file and adds it to the build report.

void GenerateCoverageReport(string projectName, string? configuration, string? framework, string coverageJsonFile, bool includeTitle = true)

Parameters

projectName string

The name of the project for which coverage was generated.

configuration string

The build configuration (e.g., "Release", "Debug").

framework string

The target framework (e.g., "net8.0").

coverageJsonFile string

The path to the JSON code coverage summary file.

includeTitle bool

Whether to include a title in the generated report data.

GenerateTestReport(string, string?, string?, string, bool)

Generates a test report from a TRX file and adds it to the build report.

[UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode", Justification = "Deserialized type `TestRun` is manually preserved via DynamicallyAccessedMembers.")]
void GenerateTestReport(string projectName, string? configuration, string? framework, string trxFile, bool includeTitle = true)

Parameters

projectName string

The name of the project that was tested.

configuration string

The build configuration (e.g., "Release", "Debug").

framework string

The target framework (e.g., "net8.0").

trxFile string

The path to the TRX test results file.

includeTitle bool

Whether to include a title in the generated report data.