dotCover 2020.1 Help

Analyze Coverage of Web Applications Using Console Runner

If you want to automate coverage of a web application (for example, in continuous integration), you can use the dotCover console runner.

Unlike manual coverage, where you get coverage snapshots by clicking the Get Snapshot button, the console runner gets a snapshot only once the profiled process correctly finishes its work. Thus, to get a snapshot, you should either correctly stop IIS in the system or run a second instance of the console runner and explicitly send the "get snapshot and kill process" command to the first running instance. How does the second instance know about the first one? It's quite simple: when running the first instance, you specify its ID using the /Instance=<ID> argument. Then you can use this ID to send commands to the instance.

The coverage process is performed somewhat differently depending on your coverage target and whether IIS or IIS Express is used to host the application. There are three main coverage scenarios:

  1. Get coverage of a web application (IIS Express / IIS).

  2. Get coverage of tests and (optionally) web application. The application and tests are started separately.

  3. Get coverage of tests. The application is started by tests.

Get coverage of a web application (IIS Express)

  1. Using the dotCover console runner, start IIS Express and your application under coverage. For example:

    dotCover.exe cover /TargetExecutable="C:\Program Files (x86)\IIS Express\iisexpress.exe" /TargetArguments=/site:MyWebApp /systray:false /Output=coverageReport.xml /ReportType=XML /Instance=1
    Here Instance is the ID of the current dotCover.exe instance. You will use this ID to send commands to this console runner.
    The /systray:false argument makes sense in case you launch more than one IIS Express instance in parallel.

  2. In the covered application, go through the desired scenario or execute tests that do this.

  3. Run the second console runner instance that sends the "get snapshot and kill process" command to the first running instance:

    dotCover.exe send /Command=GetSnapshotAndKillChildren /Instance=1
    Here Instance is the ID of the first dotCover.exe instance you have specified in step 1.

  4. After you send the command, IIS Express and dotCover.exe instances will be stopped and the coverage snapshot will be saved.

Get coverage of a web application (IIS)

  1. Make sure you have administrative privileges on the server.

  2. Using the dotCover console runner, start coverage of the IIS service. For example:

    dotCover.exe cover-iis /Output=coverageReport.xml /ReportType=XML /Instance=1
    Here Instance is the ID of the current dotCover.exe instance. You will use this ID to send commands to this console runner.

  3. In the covered application, go through the desired scenario or execute tests that do this.

  4. Run the second console runner instance that sends the "get snapshot and kill process" command to the first running instance:

    dotCover.exe send /Command=GetSnapshotAndKillChildren /Instance=1
    Here Instance is the ID of the first dotCover.exe instance you have specified in step 2.

  5. After you send the command, the IIS service and dotCover.exe instances will be stopped and the coverage snapshot will be saved.

Get coverage of tests if the application and tests are run separately

  1. Make sure you have administrative privileges on the server.

  2. Make sure the application is not already running in an instance of IIS Express or IIS application pool.

  3. Run the application (skip this step if you want to get coverage of the application as well).

  4. Using the dotCover console runner, start coverage of subsequent .NET processes. For example:

    dotCover.exe cover-everything /Output=coverageReport.xml /ReportType=XML /Instance=1
    Here Instance is the ID of the current dotCover.exe instance. You will use this ID to send commands to this console runner.
    Note that in the cover-everything mode, the console runner will get coverage data on all managed processes that are run after it.

  5. [Only if you skipped step 3] Run the application.

  6. Run tests.

  7. Run the second console runner instance that sends the "get snapshot and kill process" command to the first running instance:

    dotCover.exe send /Command=GetSnapshotAndKillChildren /Instance=1
    Here Instance is the ID of the first dotCover.exe instance you have specified in step 4.

  8. After you send the command, IIS Express and dotCover.exe instances will be stopped and the coverage snapshot will be saved. Note that if the application was run in step 5 instead of step 3, the console runner will get two snapshots (one for the application and one for the tests) and merge them into a single one.

Get coverage of tests if the application is run by tests

  1. Using the dotCover console runner, start the tests under coverage. For example, if you use NUnit:

    dotcover.exe cover /TargetExecutable="C:\Program Files\NUnit 2.6\bin\nunit-console.exe" /TargetArguments=C:\MyWebApp\bin\Debug\AppTests.dll /Output=coverageReport.xml /ReportType=XML /Instance=1
    Here Instance is the ID of the current dotCover.exe instance. You will use this ID to send commands to this console runner.

  2. Test assembly setup must start the application in IIS Express / IIS app pool.

  3. Test assembly teardown must run the command:

    dotCover.exe send /Command=GetSnapshotAndKillChildren /Instance=1
    Here Instance is the ID of the first dotCover.exe instance you have specified in step 1.

  4. After the command is sent, IIS Express / IIS app pool, dotCover.exe instances, and the process that executes the tests will be stopped and the coverage snapshot will be saved.

Last modified: 27 May 2020