BoilermakerRV
BoilermakerRV

Reputation: 389

Run coverage test with dotCover on ASP.NET application

I have written a series of tests against the front end of my web application. I really wanted to know what my test coverage looked like, so I downloaded and installed ReSharper and dotCover. These work great with the unit tests associated with my application library, but I am really struggling to get the coverage results of my front end code.

I've tried:

  1. Launching the application (without debugging) in IIS Express within Visual Studio, right clicking my front end tests and selecting "Cover Unit Tests". The tests complete successfully, but the coverage still shows 0%.

  2. IIS Express option from dotCover's new run configuration:
    Extensions -> ReSharper -> Cover -> Cover Application
    IIS Express -> Next
    Configuration file: <solutionFolder>\.vs\<projectName>\config\applicationhost.config Site: <ProjectName>
    Open URL: https://localhost:44377/
    Save
    Process Filters: Default
    Start
    Right click front end tests and select "Cover Unit Tests".

    The tests fail and the application returns the error "HTTP Error 500.31 - Failed to load ASP.NET Core runtime"

  3. Launching an external instance of IIS express via PowerShell. Borrowing from this answer, I created a PowerShell script to launch IIS Express. The application starts, but I get the same "HTTP Error 500.31 - Failed to load ASP.NET Core runtime" error.

I have installed the .NET 8 hosting bundle in addition to the SDK. I have both Microsoft.AspNetCore.App 8.0.6 and Microsoft.NETCore.App 8.0.6.

The application runs just fine when starting with Visual Studio. I'm convinced that it's just something wrong with my "Launch Settings" when I try to start IIS Express with dotCover or PowerShell. However, I can't determine the exact issue.

Upvotes: 0

Views: 384

Answers (1)

BoilermakerRV
BoilermakerRV

Reputation: 389

Seems I was missing a few environment variables. I added the following to my dotCover run configuration:

ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
LAUNCHER_ARGS=exec <path to ASP dll>
LAUNCHER_PATH=C:\Program Files\dotnet\dotnet.exe

Then IIS Express started as expected. Then I ran my playwright tests. When complete, you click the "Take snapshot and wait" button to save the snapshot.

Now I just need to figure out how to run my library and front end tests via command line. Right now, I'm running each individually and then having to manually merge the two results. I'd like to make this one process using dotCover command line.

Upvotes: 0

Related Questions