Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0% code coverage and error in collector #1661

Open
tiwarishubham635 opened this issue May 28, 2024 · 0 comments
Open

0% code coverage and error in collector #1661

tiwarishubham635 opened this issue May 28, 2024 · 0 comments
Labels
untriaged To be investigated

Comments

@tiwarishubham635
Copy link

We have a C# project - https://github.com/twilio/twilio-csharp. We were earlier calculating coverage using these steps:

dotnet sonarscanner begin /k:"$(PROJECT_NAME)" /o:"twilio" /d:sonar.host.url=https://sonarcloud.io /d:sonar.token="${SONAR_TOKEN}"  /d:sonar.language="cs" $(SONAR_SOURCES) /d:sonar.cs.opencover.reportsPaths="test/lcov.opencover.xml" /d:"sonar.verbose=true"
# Write to a log file since the logs for build with sonar analyzer are pretty beefy and travis has a limit on the number of log lines
dotnet build Twilio.sln > buildsonar.log
dotnet test test/Twilio.Test/Twilio.Test.csproj --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=../lcov
dotnet sonarscanner end /d:sonar.token="${SONAR_TOKEN}"

And were using msbuild for coverage in test.csproj like this

This was giving 0% code coverage like this:

Calculating coverage result...
   Generating report '/home/runner/work/twilio-csharp/twilio-csharp/test/lcov.opencover.xml'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+
| Twilio | 0%   | 0%     | 0%     |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 0%   | 0%     | 0%     |
+---------+------+--------+--------+
| Average | 0%   | 0%     | 0%     |
+---------+------+--------+--------+

Then i came across this known issue and shifted to use coverlet.collectors. I am using it like this:

dotnet sonarscanner begin /k:"$(PROJECT_NAME)" /o:"twilio" /d:sonar.host.url=https://sonarcloud.io /d:sonar.login="${SONAR_TOKEN}"  /d:sonar.language="cs" $(SONAR_SOURCES) /d:sonar.cs.opencover.reportsPaths="test/lcov.opencover.xml"
# Write to a log file since the logs for build with sonar analyzer are pretty beefy and travis has a limit on the number of log lines
dotnet build Twilio.sln > buildsonar.log
dotnet test test/Twilio.Test/Twilio.Test.csproj --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=../lcov --collect:"XPlat Code Coverage"
dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}"

My Test.csproj file looks like this now.

Now I am stuck with this error:

Error: /home/runner/work/twilio-csharp/twilio-csharp/test/Twilio.Test/Program.cs(9,20): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. [/home/runner/work/twilio-csharp/twilio-csharp/test/Twilio.Test/Twilio.Test.csproj]

Here are the complete logs, if you can see.

I would like to know why is this failing and is there any fix available for msbuild as well? Thanks!

@github-actions github-actions bot added the untriaged To be investigated label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged To be investigated
Projects
None yet
Development

No branches or pull requests

1 participant