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

Exclude argument is not working for dotnet test command #613

Closed
venkikonda opened this issue Nov 8, 2019 · 13 comments
Closed

Exclude argument is not working for dotnet test command #613

venkikonda opened this issue Nov 8, 2019 · 13 comments
Labels
question This issue is a question

Comments

@venkikonda
Copy link

venkikonda commented Nov 8, 2019

Hi Team,
Greetings For The Day!!

we are using coverlet.Msbuild package to get the code coverage for .NetCore.
when i executed the dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[wwwroot.]" command from test folder able to retrieve the coverage.xml for code module ( Models ..controllers etc) ..i am not able to exclude some folders which are having more lines of code ..

used pattern : dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude=[BSH.MES.CloudGateway.*.wwwroot]

need to exclude whole wwwroot folder from ../home/MES/mes-platform/services/BSH.MES.CloudGateway/wwwroot path which has 460000 lines of code

Could you please kindly assist on this how to exclude not required folders fro project?
Your help would be more appreciable here.

Thanks
Venkat
+91-8886710001

@venkikonda venkikonda changed the title Exclude argument is not working from dotnet test command Exclude argument is not working for dotnet test command Nov 8, 2019
@petli
Copy link
Collaborator

petli commented Nov 8, 2019

Exclude works on assembly names, which wwwroot is probably not a part of, if you need to exclude based on path you should look at ExcludeByFile according to the docs:
https://github.com/tonerdo/coverlet/blob/master/Documentation/MSBuildIntegration.md#source-files

@MarcoRossignoli MarcoRossignoli added the question This issue is a question label Nov 8, 2019
@MarcoRossignoli
Copy link
Collaborator

Also you need to use last version to be sure that exclude by file works correctly 2.7.0 #524

@venkikonda
Copy link
Author

@MarcoRossignoli and @petli

Thanks much for your inputs on this issue.
let me try ExcludeByFiles parameter to exclude source files and will come back to you .

if you have installation link to 2.7.0 for coverlet ..please proide me that i can use it.

@venkikonda
Copy link
Author

@MarcoRossignoli and @petli

I got the package installation command ..will try and let you guys know..

dotnet add package coverlet.msbuild --version 2.7.0

@venkikonda
Copy link
Author

@MarcoRossignoli and @petli

I have installed the latest version of coverlet-2.7.0 and tried to exclude the source folder wwwroot from the dot-net command and able to exclude from coverage.

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:ExcludeByFile="../BSH.MES.CloudGateway/wwwroot/.html,../Constants/**/.cs,../Contollers//*.cs,../Exceptions//.cs,../BSH.MES.CloudGateway/wwwroot/css/.css,../BSH.MES.CloudGateway/wwwroot/js/*.js"
wile executing sonar end analysis i could see wwwroot excluded from code module .

INFO: Excluded sources:
INFO: ../BSH.MES.CloudGateway/wwwroot/.html,../Constants//.cs,../Contollers//.cs,../Exceptions//.cs,../BSH.MES.CloudGateway/wwwroot/css/.css,../BSH.MES.CloudGateway/wwwroot/js/.js

I could see sonar.exclusions property in the sonar-project file .

sonar.exclusions="../BSH.MES.CloudGateway/wwwroot/.html,../Constants//.cs,../Contollers//.cs,../Exceptions//.cs,../BSH.MES.CloudGateway/wwwroot/css/.css,../BSH.MES.CloudGateway/wwwroot/js/.js"

But After pushing end analysis to sonar dashboard , i could see wwwroot folder which should not push which having 45000 lines of code which dev team is not covering.

could you please suggest on it why wwwroot folder is pushing though we ignored..

code structure:

root@ip-172-31-5-249:/home/MES-FETCH/services/BSH.MES.CloudGateway# ls -ltr
total 52
-rwxrwxrwx 1 root root 2991 Nov 11 11:34 README.md
drwxrwxrwx 2 root root 4096 Nov 11 11:34 Properties
-rwxrwxrwx 1 root root 4341 Nov 11 11:34 Program.cs
drwxrwxrwx 3 root root 4096 Nov 11 11:34 Models
drwxrwxrwx 2 root root 4096 Nov 11 11:34 Exceptions
-rwxrwxrwx 1 root root 454 Nov 11 11:34 Dockerfile
drwxrwxrwx 2 root root 4096 Nov 11 11:34 Controllers
drwxrwxrwx 2 root root 4096 Nov 11 11:34 Constants
-rwxrwxrwx 1 root root 1410 Nov 11 11:34 BSH.MES.CloudGateway.csproj
drwxrwxrwx 5 root root 4096 Nov 11 11:34 wwwroot
drwxrwxrwx 3 root root 4096 Nov 11 11:36 obj
drwxrwxrwx 3 root root 4096 Nov 11 11:36 bin
root@ip-172-31-5-249:/home/MES-FETCH/services/BSH.MES.CloudGateway#

@MarcoRossignoli
Copy link
Collaborator

@venkikonda can you enable coverlet logging so we can check if the parameter are correct.
You're using dotnet test so you can follow this guide https://github.com/tonerdo/coverlet/blob/master/Documentation/Troubleshooting.md#msbuild-integration (msbuild integration)
with -verbosity:diagnostic -bl:msbuild.binlog -noconsolelogger msbuil will log a file msbuild.binlog and with tool http://msbuildlog.com/ we can check if exclusion parameters come in a correct way to coverlet.

@venkikonda
Copy link
Author

@MarcoRossignoli - I have gone through the links provided by you but i am unable to see any exclusions in generated msbuild.binlog file.

I have used the below command ,

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:ExcludeByFile="../BSH.MES.CloudGateway/wwwroot/.html,../Constants/**/.cs,../Contollers//*.cs,../Exceptions//.cs,../BSH.MES.CloudGateway/wwwroot/css/.css,../BSH.MES.CloudGateway/wwwroot/js/*.js" -verbosity:diagnostic -bl:msbuild.binlog -noconsolelogger

please find the below attached reference link ..

msbuild-binlog.zip

Could you please let me know if you need any other information.

@MarcoRossignoli
Copy link
Collaborator

Try with

/p:ExcludeByFile="**/BSH.MES.CloudGateway/wwwroot/.html,**/Constants/**/.cs,**/Contollers//*.cs,**/Exceptions//.cs,**/BSH.MES.CloudGateway/wwwroot/css/.css,**/BSH.MES.CloudGateway/wwwroot/js/*.js"

The filter should be one of https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.filesystemglobbing.matcher?view=dotnet-plat-ext-3.0

and from your log I don't see any file filtered, seem that filter is not correct.
image

@venkikonda
Copy link
Author

venkikonda commented Nov 13, 2019

@MarcoRossignoli
Thank you so mush for your response!
I appreciate your help on this..

I used the below filter command in the dotnet test command.
for me "," was not worked so that i have used %2c .

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:ExcludeByFile="**/BSH.MES.CloudGateway/wwwroot/.html%2c **/BSH.MES.CloudGateway/wwwroot/css/.css%2c **/BSH.MES.CloudGateway/wwwroot/js/*.js" -verbosity:diagnostic -bl:msbuild.binlog -noconsolelogger

I am able to excluded files filter in log file..please see attached log file..
coverletlog

But still while doing sonar end analysis for dotnet .Core wwwroot whole folder pushing to sonar dashboard..

Please find below sonar dashboard image..
sonar

Please give your inputs on this..

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Nov 21, 2019

@venkikonda sorry for the delay, bit busy,
for command dotnet test /p:collectCoverage=true /p:excludebyfile="**/*.cs" (done on root of coverlet repo)
you should see
image

So seem the filter is not correct...try with /p:excludebyfile="**/wwwroot/*.*" `

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jan 8, 2020

@venkikonda any news?
Feel free to close if solved.

@MarcoRossignoli
Copy link
Collaborator

Close for stale conversation, feel free to re-open if needed!

@vsix27
Copy link

vsix27 commented Apr 22, 2024

if you put notation according to https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#source-files, it should work - escape " by backslash -
instead of
/p:ExcludeByFile="**/Properties/Resources.*,**/Program.cs"
put
/p:ExcludeByFile=\"**/Properties/Resources.*,**/Program.cs\"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This issue is a question
Projects
None yet
Development

No branches or pull requests

4 participants