Closed jstedfast closed 10 months ago
I should probably mention that dotnet test UnitTests\UnitTests.csproj
by itself works (which is why I switched to that method), but once I add in /p:AltCover=true
, it fails.
When I was using OpenCover, I was running the OpenCover tool directly with the NUnit.ConsoleRunner command-line arguments. I may have to do something similar with AltCover. I was just hoping the simplified dotnet test
approach would work to simplify things a ton :-)
I may have figured out how to do things properly:
dotnet AltCover -i=$OutputDir --inplace -s="System.*" -s="Microsoft.*" -s="Org.BouncyCastle.*" -s="Mono.*"
-s="NUnit*" -s="AltCover.*" -s="testhost" -s="UnitTests"
dotnet AltCover Runner --recorderDirectory=$OutputDir --executable=$NUnitConsoleRunner --summary=O --
--domain:single $UnitTestsAssembly
Question:
Can I just invoke the NUnut Console Runner instead of doing dotnet AltCover Runner? It looked like a coverage.xml was generated, but I'm not sure if that contained everything or not.
The latest testhost
release does cause problems like that; excluding the whole third-party stack from instrumentation as you have done - by whatever filtering method - is the thing to do.
As to the question - yes, you can run the tests as a separate stage between instrumenting the code and collecting the coverage data. The option to run tests as a sub-process is there purely as a convenience, if that should suit existing build & test processes.
FWIW, I've got AltCover working and reporting everything to coveralls successfully and here's how I managed to do it:
dotnet AltCover -i="bin\Debug\net6.0" --inplace -s="System.*" -s="Microsoft.*" -s="BouncyCastle.*" -s="NUnit*" -s="AltCover.*" -s="testhost" -s="UnitTests"
nunit3-console.exe --domain:single "bin\Debug\net6.0\UnitTests.dll"
As far as I'm concerned, this can be closed
That is in fact how the earliest implementation (in 2010) would have worked, and is good because you're directly running tests with NUnit
.
The whole Runner
appendage and intermediate files is entirely a workround for the behaviour of vstest.exe
(aka dotnet test
) in swiftly terminating end of execution handlers, such as altcover
uses to write the in-memory coverage data into the XML report when the test process terminates. These days, alas, dotnet test
is the majority case, so has to be catered for.
I'm trying to switch MimeKit from OpenCover to AltCover and I'm running into the following issue:
Any idea what I'm doing wrong or what I could try to resolve this?
This is the change I made: https://github.com/jstedfast/MimeKit/commit/3928b53b70bc803f910b1a76690f6162b3986322
Also, I'm wondering if I could simplify the AssemblyExcludeFilter down to "?MimeKit.dll" so that only MimeKit.dll gets code coverage data.
Thanks.