SteveGilham / altcover

Cross-platform coverage gathering and processing tool set for dotnet/.Net Framework and Mono
MIT License
494 stars 17 forks source link

.../Temp/tmp###.altcover.runsettings not found Intermittent tests ignored. #215

Closed StevePy closed 2 months ago

StevePy commented 3 months ago

I have been trying to validate & fix this issue for a while now but I haven't found much in the way of others having this issue which is strange. I have a Powershell script to run the tests and generate a report using ReportBuilder. This usually works, but increasingly often it is generating an incomplete report, due to not generating results for one or more unit test projects leading to underreported test coverage.

The script in question:

dotnet build QH.PSS.sln -c DEBUG

dotnet test --no-build /p:AltCover=true /p:AltCoverReport="./Coverage/coverage.xml" /p:AltCoverLocalSource=true /p:AltCoverAssemblyExcludeFilter="Microsoft|testhost|NUnit3.TestAdapter|AltCover.Monitor|^(?!(QH.PSS.))." /p:AltCoverAttributeFilter=ExcludeFromCodeCoverage /p:AltCoverVisibleBranches=true /p:AltCoverShowGenerated=false /p:AltCoverFileFilter=".cshtml.|.dependencies." /p:AltCoverTypeFilter="AspNetCoreGeneratedDocument." /p:AltCoverForce=true /p:settings=codecoverage.runsettings

The error appears in the run output similar to:

 ==== Alternative Results (includes all methods including those without corresponding source) ====
 Alternative Visited Classes 0 of 3 (0)
 Alternative Visited Methods 0 of 4 (0)
 => F:\GitRepositories\PSS\QH.PSS\QH.PSS.RSOPortal.UnitTests\bin\Debug\net8.0\QH.PSS.Logging.dll
 Alternative maximum CRAP score 2
 => F:\GitRepositories\PSS\QH.PSS\QH.PSS.RSOPortal.UnitTests\bin\Debug\net8.0\QH.PSS.MVC.dll
 => F:\GitRepositories\PSS\QH.PSS\QH.PSS.Content.UnitTests\bin\Debug\net8.0\QH.PSS.Domain.EF.dll
 => F:\GitRepositories\PSS\QH.PSS\QH.PSS.RSOPortal.UnitTests\bin\Debug\net8.0\QH.PSS.RSOPortal.dll
 => F:\GitRepositories\PSS\QH.PSS\QH.PSS.RSOPortal.UnitTests\bin\Debug\net8.0\QH.PSS.RSOPortal.UnitTests.dll
 dotnet : The Settings file 'C:\Users\***\AppData\Local\Temp\tmpnm0f2i.altcover.runsettings' could not be found.
 At F:\GitRepositories\PSS\QH.PSS\CodeCoverageGenerate.ps1:3 char:1
 dotnet test --no-build /p:AltCover=true /p:AltCoverReport="./Coverage ...

 CategoryInfo          : NotSpecified: (The Settings fi...d not be found.:String) [], RemoteException
 FullyQualifiedErrorId : NativeCommandError

F:\GitRepositories\PSS\QH.PSS\QH.PSS.Domain.EF.UnitTests\bin\Debug\net8.0__Instrumented_QH.PSS.Domain.EF.UnitTests\QH.PSS.Common.dll <= QH.PSS.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Coverage Report: F:\GitRepositories\PSS\QH.PSS\QH.PSS.Logging.UnitTests\Coverage\coverage.xml

While running the test script I can see that various tmp###.altcover.runsettings files are being created and then deleted. What I haven't been able to confirm is whether when this error occurs is it a case where the file does not get generated for some reason, or a case that it is perhaps deleted before the run actually tries to read from it. (I.e. some form of race condition) I have tried the option to run the tests in the working directory but I get the error around the .g.ReportGenerator.dll or such being in use. Is there some way to get the run to skip the step to delete the tmp###.altcover.runsettings file? This would clear up whether the issue is the file not being created vs. deleted too soon.

The tests are split across around 8 test projects within a solution. Rebuilding the solution and re-running the tests once or a few times usually sees the complete test run get through without an error. Sometimes I can run it multiple times without an error, other times it will fail 4+ times in a row with various incomplete results depending on which test project(s) does not get included in the results. Originally this issue was happening more frequently before adding the explicit build and using the --no-build option but that may have been a coincidence with the apparent intermittent failures.

SteveGilham commented 3 months ago

This sounds like this issue, which the latest (v8.7.3) release was intended to address. Which version are you currently using?

SteveGilham commented 2 months ago

Closing, believed fixed.