Create some documentation #41
Comments
Also make sure it is available from the program menu along with a console cmd window to start in that folder to help people get going. |
Hi, I don't really know where to ask this question (hope here is OK), but is it possible at all to exclude methods? I've got the latest Release2 bleeding edge but can't seem to work it out...I'm probably missing something obvious. For example I have Test.Testy.TestMe::bleh() How would I exclude bleh()? Thanks for your help. :) |
Have you got the installer - or compiled the code? There is an excludebyattribute option (#37) which can deal with such exclusions but has not been released in an installer and can only be found on the Release2 branch. |
I'm currently using the compiled code. I've tried to use the excludebyattribute option but I can't seem to get it to work, using an example: Test.Testy.TestMe::dummyMethod() How would I exclude dummyMethod()? I've tried excludebyattribute:dummyMethod() Unfortunatly that does not seem to work, I guess I'm missing something obvious. Thanks again for your help. :) |
Hi If you have compiled the code yourself then you will need to do so on the release2 branch. What you need is a custom attribute that you can apply to the method(s) that you want to exclude. It is the name of that attribute that you put into the filter
then mark up your method
and then pass that into the command line
It is a recent feature so I haven't got round to documenting it yet as I have not 'officially' released it. |
Excellent, that did the trick. Thanks very much. :) |
Hello Shaun, thanks exec { iex "$opencover -targetdir:$buildPath ""-target:$nunit"" ""-targetargs:$dlls /noshadow"" ""-output:$outputPath$stage\Coverage.xml"" ""-excludebyattribute:CoverageExclude"" ""-filter:+[P_]_ "" "} "Test Coverage failed" namespace Infrastructure.RestClient using System; // ReSharper disable CheckNamespace |
What error are you seeing or what is not happening that you expect? I notice the attribute has no AttributeUsage set on it, in your supplied code. |
It does not exclude the type. I added this but it is still the same. |
When you say it does not exclude the type, can you show me the part of the report where it is showing - just a snippet. |
|
I use ReportGenerator and it creates a full red report for this type (which is not under any test). |
I'll have to investigate... is the attribute in a namespace? |
no there is no namespace for attribute. |
this full parameter list that I am using. before exclude by attribute feature I was using filter in commandline and now I am trying to use both exclusion methods. maybe that can be a problem? I will investigate opencover source code tonight. If I found something I will let you know. exec { iex "$opencover -targetdir:$buildPath ""-target:$nunit"" ""-targetargs:$dlls /noshadow"" ""-output:$outputPath$stage\Coverage.xml"" ""-excludebyattribute:CoverageExclude"" ""-filter:+[P_]_ -[]ApiConfiguration* -[]Registry -[]Bootstrapper -[]ProjectInstaller -[]Program -[]Global -[]CompanyName.Domain. -[]CompanyName.PRODUCTNAME.Data.Mappings. -[]CompanyName.PRODUCTNAME.Data.Model. -[]CompanyName.BR.Data.Model. -[]DataMap -[]DataMapGroup -[]DataMappingGroupCodes -[]FeedSettings -[]CoverageExcludeAttribute -[Moq] -[StructureMap]* -[CompanyName.UnitTests]* -[CompanyName.IntegrationTests]* -[FluentNHibernate]* -[_]TemplateMapping -[]_RequestBase"" "} "Test Coverage failed" |
Is the attribute in the same assembly or a different assembly to the code it is being applied to? |
this test it is in the same, but it will not be in most cases. |
I have just tried the same steps as you describe
I then used the -excludebyattribute:GlobalExcludeFromCoverage option (unusual formatting in emails may be due to markdown) And I got the following output in my report for the class I applied to be excluded
Can you supply me with a sample that repeats the issue at all? |
I think problem is in ReportGenerator side. I am able get same output as you. I have tried latest version of reportgenerator but it still show as %0 percentage. |
if I use filter from commandline to exclude opencover does not include any information about type in the xml output but excludebyattribute behaves differently. I think consistency is necessary for these two features? |
ReportGenerator is an external tool and it may not have been updated to ignore classes with a skippedDueTo attribute. Perhaps but that would mean I would have an entry for every method and class that was ignored and that would mean all the System. assemblies - the file would get very big. The attribute is there for my own internal usage (as I actually dislike the capability and how it can be misused and how I have seen a similar feature misused in other coverage tools) so I can report on it. It wouldn't be hard to update ReportGenerator to ignore the class - raise the issue on the ReportGenerator site and I am sure Daniel will fix it. |
sent a patch to reportgenerator.codeplex.com project for ignoring classes with skippedDueTo attribute. see patch link. http://reportgenerator.codeplex.com/SourceControl/list/patches (ID:11309) |
I agree on misusing of exclude attribute, defining filter in your script gives your more control over to have accurate coverage information as a tech lead. But still I believe filters and exclude should have consistency in the xml output. actually I am thinking about working on reportgenerator to list excluded types as another output in the html. thank you for good work on opencover and being so responsive on issues Shaun. |
I suppose for classes/modules that are skipped due to filters I could add them at that level and only if I could instrument them anyway i.e. have a PDB (which would hopefully stop the amount of data due to System.* assemblies etc) |
I had a look at your patch and it would need extending to cover skipped Methods, which already happens if the attribute is applied to a property/method, and if I do the above skipped Modules. |
It's no problem to integrate and extend the patch. |
Hi Daniel I need to mark them as excluded for reporting reasons (i.e. not ReportGenerator but for use an internal report) as this classes/methods would normally be included by filters but have been excluded deliberately by a developer. There will be no sequence points so their appearance in the report should not affect actual sequence/branch coverage data. The skippedDueTo should work on methods (properties being a type of method in the metadata) as well as classes but it is a case of the highest level wins i.e. if a class is excluded then the methods in that class aren't even reported. I'll probably extend the skippedDueTo to Modules as well for similar reporting reasons which may not be needed by anyone else but me. |
Hi Shaun I tested with the following class:
But the report does not contain any "skippedDueTo" attributes. If I place the attribute on the class level, the "skippedDueTo" appears in the report. I'm using OpenCover 2.1.15.2. |
Thanks - I seem to have broken it by filtering the method out somewhere else - code is updated |
Great. I will add the filtering to ReportGenerator soon. |
I just tested with the latest changes. The excluded method now has the "skippedDueTo" attribute. |
Looks like a bug - currently I think it works if you set it directly against the get; and set; i.e. public string XYZ I need to work out why this is |
I just published ReportGenerator 1.2.5.0. It now handles excludes on all levels (module, class, method/property). |
…porting of all skipped entities with reason #41
I hope this issue is now complete with 2.1.25 - if not we should create a new issue as this one was hijacked. |
I've just checked, and the attribute one has to define must be public. If you declare it as internal, which I was doing, it wasn't picked up. My usage pattern is to have a shared .cs file for common attributes that has no namespaces and all types as |
Okay thanks for that I'll update the documentation to inform people that |
Create some documentation (probably PDF/RTF) and add it to the installer/nuget packages
The text was updated successfully, but these errors were encountered: