Code coverage is not collected for all the visits when Service is ran as command prompt console application.
I am instrumenting and collecting dotnet code coverage using steps given below. The dotnet service for which this coverage is getting collected is started as command prompt console application and not as registered windows service.
Steps for Instrumentation and collection:
- altcover --save --inplace --single -i "C:\Users\Admin\Desktop\BuildServices\OEAService"
- Starting dotnet service application
- Running testcases
- Stopping dotnet service using below powershell command:
if (Get-Process 'EAService' -ErrorAction SilentlyContinue) { Stop-Process -Name 'EAService' } - altcover runner --collect -r "C:\Users\Admin\Desktop\BuildServices\OEAService" -c="C:\Users\Admin\Desktop\CodeCoverage\OEAService\coverage.xml"
When validated if all the visits were captured correctly in Cobertua coverage.xml, it was found that it is capturing only the hits which were captured on the console application i.e., main method and not rest of the logic/methods present in that EAService.exe.
But when i am registering this service and using it for starting and stopping the EAService, then it is capturing all the hits/visits properly in coverage file.
Can you please guide as if there are any changes required in my commands for collecting all the hits of EAService.exe.
Given where the dividing line seems to lie, between code operated from the console, and code operated by the service "in flight", the obvious "Is it plugged in?" sort of question concerns the service principal. Does the identity that the service executes with have rights to create and write to files (containing the raw coverage results) in the C:Users\Admin\Desktop\CodeCoverage\OEAService directory?
The next one is whether multiple collect operations are being run from the same instrumentation, as the collect operation clears the Control File. In the case of tracking the service, manually ending coverage by deleting the control file ahead of service termination is also a reasonable use case. This differs in that detail from the how-to in the service demo , as that was written for the so-called "classic mode", where process termination writes directly to the (NCover or OpenCover formatted) coverage report.
On a related note, stopping the service via control panel or the Stop-Service cmdlet would also allow you to test the related service even driven termination paths.
@SteveGilham
I observed the following behavior in the scenario mentioned by @rinkal-chomal7 :
When I run AltCover using:
altcover --save --inplace --single -i "C:\Users\Admin\Desktop\BuildServices\OEAService"
→ Hits/visits are not fully captured.
When I run AltCover with:
altcover --save --inplace -c="3" --single -i "C:\Users\Admin\Desktop\BuildServices\OEAService"
→ Hits/visits are captured correctly, even when the EAService is running from the command line.
Concern: The -c (callContext/allContext) parameter is documented for tracking timing or context of calls, and is not directly related to coverage counts. Why does adding -c="3" result in complete coverage collection, while omitting it does not?