SeaLights .NET Core agent - Capturing coverage from the app process

There are two ways to capture coverage from the app/service processes using the SeaLights .NET Core agent

  1. By running the process with our agent using the run option (command wrapper).

  2. By running the SeaLights .NET Core agent as a background listener

The Background Listener option allows you to capture coverage from any application - without changing the command used to run it, but this requires a few more steps than the runoption.

Running the process with the SeaLights .NET Core agent using run option

To capture coverage from a single application, you can run it with the SeaLights .NET agent, which will capture coverage from it when it runs, and tests are run against it.

./sl-dotnet-agent/SL.DotNet.exe run --buildSessionIdFile buildSessionId.txt --instrumentationMode coverage --target c:\MyApplication\App.exe --workingDir c:\WorkingDir --targetArgs "-Flag1 true MyTest.dll"

The sample command above is replacing the regular command used to startup the application captured: c:\MyApplication\App.exe -Flag1 true MyTest.dll executed from the c:\WorkingDir directory

At the successful completion of this step, you will see new entries appearing in the Cockpit > Live Agents Monitor: the testListener and a entity called Profiler with the version details of your application.

Running the SeaLights .NET Core agent as a background listener

To capture coverage from any application without changing the command you use to run it, you can run the SeaLights .NET agent as a background process, which will capture coverage from any process with the SeaLights .NET agent defined as a profiler.

Starting the SeaLights .NET Core agent background listener

To run the background process, you need to use the startBackgroundTestListener flag and provide a unique session key:

dotnet ./sl-dotnet-agent/SL.DotNet.dll startBackgroundTestListener --buildSessionIdFile buildSessionId.txt --testListenerSessionKey SL_CovCollectorAgent

Setting the SeaLights .NET Core agent as a profiler

Now, you need to run (all) your processes - i.e. including your application - with the SeaLights .NET Core agent defined as a profiler. This is done by setting the following environment variables in the shell used to run your process:

.NET Core / Windows

.NET Core / Linux

.NET Core / Windows

.NET Core / Linux

[Environment]::SetEnvironmentVariable("CORECLR_ENABLE_PROFILING", "1", "Machine") [Environment]::SetEnvironmentVariable("CORECLR_PROFILER", "{01CA2C22-DC03-4FF5-8350-59E32A3536BA}", "Machine") [Environment]::SetEnvironmentVariable("CORECLR_PROFILER_PATH_32", "C:\Sealights\agent\SL.DotNet.ProfilerLib.Windows_x86.dll", "Machine") [Environment]::SetEnvironmentVariable("CORECLR_PROFILER_PATH_64", "C:\Sealights\agent\SL.DotNet.ProfilerLib.Windows_x64.dll", "Machine") [Environment]::SetEnvironmentVariable("SL_CollectorId", "SL_CovCollectorAgent", "Machine") [Environment]::SetEnvironmentVariable("SL_LogDir", "C:\Sealights\logs", "Machine") [Environment]::SetEnvironmentVariable("SL_LogLevel", "6", "Machine")

Stopping the SeaLights .NET Core agent background listener

Once you have finished collecting coverage from the process, you need to stop the background listener. This is done by using the stopBackgroundTestListener flag with the session key previously used