For the complete documentation index, see llms.txt. This page is also available as Markdown.

Running tests

Capture test execution and coverage from MSTest, NUnit, and xUnit with the SeaLights .NET Agent.

The examples below assume the self-contained agent package. If you use a framework-dependent package, replace .\sl-dotnet-agent\SL.DotNet.exe or ./sl-dotnet-agent/SL.DotNet with dotnet ./sl-dotnet-agent/SL.DotNet.dll.

Running tests with MSTest, NUnit, or xUnit

You have two ways to capture tests from a supported framework:

  • Wrap the test command with the SeaLights agent.

  • Use the Profiler-Initiated Collector, or PIC, when you cannot change the startup command.

Wrapper to the test command

When you use MSTest, NUnit, or xUnit, wrap the test runner command with the agent. The test listener tracks execution and uploads results automatically.

Here is a sample command with a Lab ID setup.

.\sl-dotnet-agent\SL.DotNet.exe run --tags "mytag" --instrumentationMode tests --labId "<lab-id>" --testStage "Functional Tests" --target "C:\tools\testrunner.exe" --workingDir (Get-Location) --targetArgs "MyTest.dll --flag1 true --flag2 false"

For in-process testing, such as unit or integration tests, remove --instrumentationMode tests or set --instrumentationMode testsAndCoverage.

See Command Reference for full parameter details.

CI examples

These examples wrap dotnet test directly in the pipeline.

PIC integration

Set the environment variables required for profiling and PIC in the same shell session that runs the tests. In the examples below, SL_AGENT_ROOT is an absolute path to the unpacked agent directory.

You can now execute the tests in the same session with the regular test command.

SL_PROFILER_INCLUDEPROCESSFILTER is intentionally omitted. A dotnet test run can start multiple child processes, and a narrow filter can attach to the wrong one.

Set the variables only in the same session that runs the test command.

Last updated

Was this helpful?