OpenCover.Console.exe not generating correct code coverage report in ASP.NET MVC 4 project (NUnit, .NET 4.8)

46 Views Asked by At

I am implementing code coverage for an ASP.NET MVC 4 project running on .NET 4.8. I am using NUnit test framework for running testcases, all testcases are running fine, but opencover.console.exe is not generating correct code coverage report showing zero coverage.

Committing...
Visited Classes 0 of 1367 (0)
Visited Methods 0 of 5806 (0)
Visited Points 0 of 36686 (0)
Visited Branches 0 of 14508 (0)

==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 0 of 1697 (0)
Alternative Visited Methods 0 of 7343 (0)

OUTPUT

Launching OpenCover 4.7.1221.0
Executing: C:\GITRepository\Delogue\Src\packages\NUnit.ConsoleRunner.3.12.0\tools\nunit3-console.exe
NUnit Console Runner 3.12.0 (.NET 2.0)
Copyright (c) 2021 Charlie Poole, Rob Prouse
22 February 2024 12:24:34

Runtime Environment
   OS Version: Microsoft Windows NT 6.2.9200.0
   Runtime: .NET Framework CLR v4.0.30319.42000

Test Files
    C:\GITRepository\Delogue3\Src\DesignHub.UnitTest2\bin\Debug\net48\DesignHub.UnitTest2.dll


Run Settings
    DisposeRunners: True
    ActiveConfig: Debug
    WorkDirectory: C:\GITRepository\Delogue3\Src
    ImageRuntimeVersion: 4.0.30319
    ImageTargetFrameworkName: .NETFramework,Version=v4.8
    ImageRequiresX86: False
    ImageRequiresDefaultAppDomainAssemblyResolver: False
    TargetRuntimeFramework: net-4.0
    NumberOfTestWorkers: 8

Test Run Summary
  Overall result: Passed
  Test Count: 6, Passed: 6, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2024-02-22 06:54:34Z
    End time: 2024-02-22 06:54:46Z
    Duration: 11.700 seconds

Results (nunit3) saved as TestResult.xml
Committing...
Visited Classes 0 of 4192 (0)
Visited Methods 0 of 26335 (0)
Visited Points 0 of 118003 (0)
Visited Branches 0 of 46347 (0)

==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 0 of 4427 (0)
Alternative Visited Methods 0 of 30499 (0)

and this is my test project structure

enter image description here

this is the batch file I am using to generate the codecoverage

@echo off

REM Set paths to OpenCover and ReportGenerator executables
set OPENCOVER_EXE=OpenCover.Console.exe
set REPORTGENERATOR_EXE=ReportGenerator.exe

REM Set filter to include only controller classes
set COVERAGE_FILTER=+[DesignHub.*]*

REM Set paths to NUnit test runner and test assembly
set NUNIT_CONSOLE_EXE=nunit3-console.exe
set TEST_ASSEMBLY=C:\GITRepository\Delogue3\Src\DesignHub.UnitTest2\bin\Debug\net48\DesignHub.UnitTest2.dll
set TARGET_DIR=C:\GITRepository\Delogue3\Src\DesignHub.UnitTest2\bin\Debug\net48\DesignHub.UnitTest2.dll

REM Set output paths for coverage results and report
set COVERAGE_RESULTS_FILE=C:\GITRepository\Delogue3\Src\CoverageReportOutput3\CoverageResults.xml
set REPORT_OUTPUT_FOLDER=C:\GITRepository\Delogue3\Src\CoverageReportOutput3\CoverageReport

REM Run tests with OpenCover
"%OPENCOVER_EXE%" -target:"%NUNIT_CONSOLE_EXE%" -targetargs:"%TEST_ASSEMBLY%" -output:"%COVERAGE_RESULTS_FILE%" -filter:"%COVERAGE_FILTER%"
  1. What might be causing the incorrect code coverage report?

  2. Are there any specific configurations or settings I should check in OpenCover or the batch file?

  3. Could the project structure or test setup be contributing to the issue?

0

There are 0 best solutions below