Getting code coverage for a .Net Core application

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 application

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

You will need to build this 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 Framework dependent .Net Core applications and also how to get code coverage for self contained .Net Core applications .

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
  • 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
  • Click the Launch button to launch the application.
  • The .Net Core dotNet.exe runtime is started to run the dotNetCoreLauncher_vs2019.dll application.
    .Net Launcher, choose an application to launch
  • Whilst Coverage Validator is instrumenting the application various progress dialogs are displayed. The display of Coverage Validator updates to show the names of source code files and statistics about each file.
    Coverage Validator framework dependent results
  • Close dotNetLauncher by making a choice between 0 and 4. Any other choice repeats the menu.
  • The application closes. Coverage Validator processes any remaining data and displays the final 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

  • 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
  • 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
  • Click the Launch button to launch the application.
  • The .Net Core dotNetCoreLauncher_vs2019.exe runtime is started to run the dotNetCoreLauncher_vs2019.dll application.
    .Net Launcher, choose an application to launch
  • Whilst Coverage Validator is instrumenting the application various progress dialogs are displayed. The display of Coverage Validator updates to show the names of source code files and statistics about each file.
    Coverage Validator self contained results
  • Close dotNetLauncher by making a choice between 0 and 4. Any other choice repeats the menu.
  • The application closes. Coverage Validator processes any remaining data and displays the final 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.

 

Fully functional, free for 30 days