Getting code coverage for a .Net Core application child process

This tutorial demonstrates launching a .Net Core application, closing the application and inspecting the coverage results. 

Related tutorials:

Code coverage for a .Net Core application.
Code coverage for a .Net Core application child process.
Code coverage for a service.
Code coverage for a service child process.
Code coverage for an IIS ISAPI DLL.
Code coverage for ASP.Net with IIS.
Code coverage for ASP.Net with Web Development Server.

Building the example applications

For this tutorial we’re going to work with dotNetCoreLauncher and consoleApp which are located in <Coverage Validator install directory>\examples\dotNetCore\.

You will need to build these with Visual Studio 2019 (.Net Core 5) or Visual Studio 2022 (.Net Core 6). A solution file is provided for each version. If you’ve installed in the default program files location you’ll need to run Visual Studio in administrator mode to do the build.

We’re going to show you how to get code coverage for a child process launched from a .Net Core application. The process is the same for both Framework-dependent and Self-contained .Net Core applications. But the process is slightly different depending on whether the child process is Framework-dependent, Self-contained, .Net or native.

Publishing the application

Publishing the .Net Core application allows you to create an application that is framework dependent, or which is self contained.

The following command will create a framework dependent version and a self contained x64 version using Visual Studio 2019 and Visual Studio 2022.

Open a command prompt with administrator privileges.

cd c:\Program Files (x86)\Software Verify\Coverage Validator x64\examples\dotNetCore

publish.bat

You can also use publish_vs2019.bat and publish_vs2022.bat for use with specific versions of Visual Studio.

Framework dependent .Net Core

  • Launch the sample application. Click on the launch icon on the toolbar.
    Coverage Validator launch toolbar
  • The Launch Application or Service dialog is displayed.
    Coverage Validator launch .Net Core application ro service dialog
  • Click Launch .Net Core Applications. The Launch .Net Core application dialog is displayed. By default it is configured for Framework Dependent .Net Core applications. You can change that from the .Net Core Application Type combo. For this tutorial we’ll leave it set to Framework Dependent.
    Coverage Validator .Net Core launch dialog, framework dependent
  • We’re going to start dotNetCoreLauncher that we just built with publish.bat. This is in <Coverage Validator install dir>\examples\dotNetCore\dotNetCoreLauncher\dotNetCoreLauncher\bin\debug\net5.0\win-x64\. You may need to replace net5.0 with net6.0 on your machine.

    Select the dotNetCoreLauncher_vs2019.dll using the Browse… button next to the Application to launch (*.dll) field.

    When you do this the Application to launch (*.exe) and Application to Monitor fields are populated with the .Net Core runtime, and the Application to launch (*.dll) is populated with the choice of dll. 
    Coverage Validator .Net Core launch dialog, framework dependent

  • Now we need to specify the child process that we want to monitor. Click Edit… next to the Application to monitor (*.exe) field. 
    Coverage Validator edit application to monitor
  • The Applications to Monitor dialog is displayed.
    Coverage Validator .Net Core Applications to Monitor dialog
  • We need to add an application that we want to monitor. Click Add…
  • The Application to Monitor dialog is displayed.
    Coverage Validator .Net Core Application to Monitor dialog
  • This dialog allows us to specify the .Net Core application that is being launched and which child applications you want to monitor. The application being launched has already been configured based on your choices on the .Net Core launch dialog. You can specify as many child applications as you want. For this example we’re going to specify two child applications.
  • To add the first application click Add…. The Application and DLL dialog is displayed.
    Coverage Validator Dot Net Core Application and DLL dialog
  • We’re going to launch a .Net application, so leave the application type as it is. Click Browse… and choose <install dir>\examples\dotnetExample\bin\Release10_0\dotnetExample10_0.exe. Then click OK to accept this choice.
    Coverage Validator .Net Core Child Application .Net Example
  • To add the second application click Add…. The Application and DLL dialog is displayed.
  • We’re going to launch a self contained .Net application, so change the Application Type to .Net Core (Self Contained). Click Browse… and choose <install dir>\examples\dotNetCore\consoleApp\consoleApp\bin\Debug\net5.0\win-x64\consoleApp_vs2019.exe. Then click OK to accept this choice.
    Coverage Validator .Net Core Child Application Console App Self Contained
  • The Application to Monitor dialog should now show four entries (for two applications) in the list. Click OK.
    Coverage Validator .Net Core Application to Monitor dialog with 4 entries
  • The Applications to Monitor dialog will now show an additional entry in the list. Click OK.
    Coverage Validator .Net Core Applications to Monitor additional entry
  • Now that we have configured which child applications we want to monitor we choose an application. The Application to Monitor combo will display <<Any application that is launched>>, the name of the application we are launching, and the names of all the child applications that have been configured. You may need to widen the dialog to see the full path in the combo. Select <install dir>examples\dotNetCore\consoleApp\consoleApp\bin\Debug\net5.0\win-x64\consoleApp_vs2019.exe consoleApp_vs2019.dll.
  • Click the Launch button to launch the application.
  • The .Net Core dotNet.exe runtime is started to run the dotNetCoreLauncher_vs2019.dll application.
  • Coverage Validator displays no coverage information because although an application has been started that is not the application we are monitoring.
    Coverage Validator .Net Core launcher
  • Choose 2 to launch dotNetExample. dotNetExample is launched but code coverage is not collected because you didn’t choose dotNetExample in the Application to Monitor combo. Close dotNetExample.
  • Choose 5 to launch the win-x64 configuration of self contained .Net Core consoleApp_vs2019.exe. consoleApp_vs2019.exe is launched and Coverage Validator starts collecting code coverage.
  • Choose 0 to exit consoleApp_vs2019.exe.
  • The application closes. Coverage Validator processes any remaining data and displays the final results.
    Coverage Validator .Net Core child process Results
  • The coverage results are displayed on the SummaryCoverage, Branch Coverage, Functions, Directories, DLLs and Files and Lines tabs. These have been discussed in previous tutorials, we will not repeat that discussion here.

Self Contained .Net Core

The process for self contained .Net Core is very similar to the process described above for Framework Dependent .Net Core.

The difference is just how you specify the application to launch.

How you specify the child processes to monitor is identical to the process for Framework Dependent .Net Core.

  • Launch the sample application. Click on the launch icon on the toolbar.
    Coverage Validator launch toolbar
  • The Launch Application or Service dialog is displayed.
    Coverage Validator launch .Net Core application ro service dialog
  • Click Launch .Net Core Applications. The Launch .Net Core application dialog is displayed. Change the .Net Core application type to Self Contained using the .Net Core Application Type combo. 
    Coverage Validator .Net Core launch dialog self contained
  • We’re going to start dotNetCoreLauncher that we just built with publish.bat. This is in <Coverage Validator install dir>\examples\dotNetCore\dotNetCoreLauncher\dotNetCoreLauncher\bin\debug\net5.0\win-x64\. You may need to replace net5.0 with net6.0 on your machine.

    Select the dotNetCoreLauncher_vs2019.exe using the Browse… button next to the Application to launch (*.exe) field.

    When you do this the Application to launch (*.dll) and Application to Monitor fields are populated with the executable, and the Application to launch (*.dll) is populated with a .Net Core dll that has the same name as the executable. 
    Coverage Validator .Net Core launch dialog, self contained

  • From this point on, please follow the tutorial process described above for Framework Dependent .Net Core, starting with Now we need to specify the child process that we want to monitor.

Fully functional, free for 30 days