This is a recurring project for coverlet-coverage/coverlet#922 (The type of dependency injection does not recognize coverage)
- Calling
Program.CreateHostBuilder(new string[0]).ConfigureWebHost(webBuilder => { }).Start();
(static constructor/constructor) from the unit test class base class results inImplement
project coverage of 0. - Calling (static constructor/constructor /TestInitialize) from the unit test class does not occur (However, it will cause coverage recognition of this class to fail, and other normal test classes to recognize normal) (see: TestIWeekLogic.cs)
- Based on the above situation, I think
Program.CreateHostBuilder(new string[0]).ConfigureWebHost(webBuilder => { }).Start();
will lead to the failure of test class coverage identification - If you are using Visual Studio 2019, all of the above can be identified normally
- The problem
HostingAbstractionsHostBuilderExtensions.Start(this IHostBuilder hostBuilder);
, just change it toIHostBuilder.Build();
.UsingProgram.CreateHostBuilder(new string[0]).ConfigureWebHost(webBuilder => { }).Build();
replaceProgram.CreateHostBuilder(new string[0]).ConfigureWebHost(webBuilder => { }).Start();
.I can't explain the deeper reason, if anyone knows, please let me know, I'd appreciate it
- This is the
Implement
failure case for all test classes - This is a case of just
TestIWeekLogic
failing - This is the normal case of
- This is a comparison of Visual Studio 2019 in case
1
- Visual Studio 2019
- Open project
Coverlet.Console.TestProject.sln
using Visual Studio 2019 - Top menu bar "Test(S) -> Analyze code coverage for all tests(C)"
- See the results in "Code coverage Results" displayed
- Open project
- coverlet.console
- run Coverlet.Console.Test.bat
- View the results in the console window that pops up
- This document is a translation version, original text see: README_zh-cn