Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Create some documentation #41

Closed
sawilde opened this issue Sep 9, 2011 · 36 comments
Closed

Create some documentation #41

sawilde opened this issue Sep 9, 2011 · 36 comments
Assignees
Labels
Milestone

Comments

@sawilde
Copy link
Member

sawilde commented Sep 9, 2011

Create some documentation (probably PDF/RTF) and add it to the installer/nuget packages

@ghost ghost assigned sawilde Sep 9, 2011
@sawilde
Copy link
Member Author

sawilde commented Sep 25, 2011

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.

@sawilde sawilde reopened this Sep 27, 2011
@reacz
Copy link

reacz commented Jan 4, 2012

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. :)

@sawilde
Copy link
Member Author

sawilde commented Jan 4, 2012

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.

@sawilde sawilde closed this as completed Jan 4, 2012
@sawilde sawilde reopened this Jan 4, 2012
@reacz
Copy link

reacz commented Jan 4, 2012

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. :)

@sawilde
Copy link
Member Author

sawilde commented Jan 5, 2012

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

[AttributeUsage(AttributeTargets.Method|AttributeTargets.Property)]
public class ExcludeFromCoverageAttribute : Attribute{}

then mark up your method

class MyClass
{
    [ExcludeFromCoverage]
    void dummyMethod()
    {
    }
}

and then pass that into the command line

-excludebyattribute:*.ExcludeFromCoverage*

It is a recent feature so I haven't got round to documenting it yet as I have not 'officially' released it.

@reacz
Copy link

reacz commented Jan 5, 2012

Excellent, that did the trick. Thanks very much. :)

@hancengiz
Copy link

Hello Shaun,
I am trying to upgrade v2 for excludebyattribute featue but it does not work for me. Can you tell me what is the problem with below snippet?

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
{
[CoverageExclude]
public class HttpClient : IHttpClient { ... }
}

using System;

// ReSharper disable CheckNamespace
public class CoverageExcludeAttribute : Attribute
// ReSharper restore CheckNamespace
{
public CoverageExcludeAttribute() { }
}

@sawilde
Copy link
Member Author

sawilde commented Jan 18, 2012

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.

@hancengiz
Copy link

It does not exclude the type.

I added this but it is still the same.
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Class)]

@sawilde
Copy link
Member Author

sawilde commented Jan 18, 2012

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.

@hancengiz
Copy link

    <Class>
      <FullName>CompanyName.Infrastructure.RestClient.HttpClient</FullName>
      <Methods>
        <Method visited="false" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="true" isStatic="false" isGetter="false" isSetter="false">
          <MetadataToken>100663368</MetadataToken>
          <Name>System.Void CompanyName.Infrastructure.RestClient.HttpClient::.ctor()</Name>
          <FileRef uid="135" />
          <SequencePoints>
            <SequencePoint vc="0" uspid="1378" ordinal="0" offset="0" sl="15" sc="9" el="15" ec="28" />
            <SequencePoint vc="0" uspid="1379" ordinal="1" offset="6" sl="18" sc="13" el="21" ec="32" />
            <SequencePoint vc="0" uspid="1380" ordinal="2" offset="30" sl="22" sc="9" el="22" ec="10" />
          </SequencePoints>
          <BranchPoints />
          <MethodPoint xsi:type="SequencePoint" vc="0" uspid="1378" ordinal="0" offset="0" sl="15" sc="9" el="15" ec="28" />
        </Method>
        <Method visited="false" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
          <MetadataToken>100663369</MetadataToken>
          <Name>T CompanyName.Infrastructure.RestClient.HttpClient::Get(System.String)</Name>
          <FileRef uid="135" />
          <SequencePoints>
            <SequencePoint vc="0" uspid="1381" ordinal="0" offset="0" sl="25" sc="13" el="25" ec="59" />
            <SequencePoint vc="0" uspid="1382" ordinal="1" offset="13" sl="26" sc="13" el="26" ec="69" />
            <SequencePoint vc="0" uspid="1383" ordinal="2" offset="25" sl="27" sc="13" el="27" ec="25" />
            <SequencePoint vc="0" uspid="1384" ordinal="3" offset="31" sl="28" sc="13" el="28" ec="32" />
          </SequencePoints>
          <BranchPoints />
          <MethodPoint xsi:type="SequencePoint" vc="0" uspid="1381" ordinal="0" offset="0" sl="25" sc="13" el="25" ec="59" />
        </Method>
        <Method visited="false" cyclomaticComplexity="1" sequenceCoverage="0" branchCoverage="0" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
          <MetadataToken>100663370</MetadataToken>
          <Name>CompanyName.Infrastructure.RestClient.HttpClientResponse CompanyName.Infrastructure.RestClient.HttpClient::Post(System.String,System.String)</Name>
          <FileRef uid="135" />
          <SequencePoints>
            <SequencePoint vc="0" uspid="1385" ordinal="0" offset="0" sl="33" sc="13" el="33" ec="56" />
          </SequencePoints>
          <BranchPoints />
          <MethodPoint xsi:type="SequencePoint" vc="0" uspid="1385" ordinal="0" offset="0" sl="33" sc="13" el="33" ec="56" />
        </Method>
        <Method visited="false" cyclomaticComplexity="2" sequenceCoverage="0" branchCoverage="0" isConstructor="false" isStatic="false" isGetter="false" isSetter="false">
          <MetadataToken>100663372</MetadataToken>
          <Name>System.Void CompanyName.Infrastructure.RestClient.HttpClient::SetRequestData(System.String)</Name>
          <FileRef uid="135" />
          <SequencePoints>
            <SequencePoint vc="0" uspid="1386" ordinal="0" offset="0" sl="58" sc="13" el="58" ec="51" />
            <SequencePoint vc="0" uspid="1387" ordinal="1" offset="8" sl="58" sc="52" el="58" ec="59" />
            <SequencePoint vc="0" uspid="1388" ordinal="2" offset="9" sl="60" sc="13" el="60" ec="76" />
            <SequencePoint vc="0" uspid="1389" ordinal="3" offset="21" sl="61" sc="13" el="61" ec="69" />
            <SequencePoint vc="0" uspid="1390" ordinal="4" offset="36" sl="62" sc="13" el="63" ec="72" />
            <SequencePoint vc="0" uspid="1391" ordinal="5" offset="57" sl="64" sc="9" el="64" ec="10" />
          </SequencePoints>
          <BranchPoints>
            <BranchPoint vc="0" uspid="1392" ordinal="0" offset="6" path="0" />
            <BranchPoint vc="0" uspid="1393" ordinal="1" offset="6" path="1" />
          </BranchPoints>
          <MethodPoint xsi:type="SequencePoint" vc="0" uspid="1386" ordinal="0" offset="0" sl="58" sc="13" el="58" ec="51" />
        </Method>
      </Methods>
    </Class>

@hancengiz
Copy link

I use ReportGenerator and it creates a full red report for this type (which is not under any test).

@sawilde
Copy link
Member Author

sawilde commented Jan 18, 2012

I'll have to investigate... is the attribute in a namespace?

@hancengiz
Copy link

no there is no namespace for attribute.

@hancengiz
Copy link

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.
thanks

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"

@sawilde
Copy link
Member Author

sawilde commented Jan 18, 2012

Is the attribute in the same assembly or a different assembly to the code it is being applied to?

@hancengiz
Copy link

this test it is in the same, but it will not be in most cases.

@sawilde
Copy link
Member Author

sawilde commented Jan 19, 2012

I have just tried the same steps as you describe

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property)]
public class GlobalExcludeFromCoverageAttribute : Attribute
{
}

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

<Class skippedDueTo="Attribute">
  <FullName>OpenCover.Framework.ExcludeFromCoverageAttribute</FullName> 
  <Methods/> 
</Class>

Can you supply me with a sample that repeats the issue at all?

@hancengiz
Copy link

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.

@hancengiz
Copy link

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?

@sawilde
Copy link
Member Author

sawilde commented Jan 20, 2012

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.

@hancengiz
Copy link

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)

@hancengiz
Copy link

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.

@sawilde
Copy link
Member Author

sawilde commented Jan 20, 2012

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)

@sawilde
Copy link
Member Author

sawilde commented Jan 20, 2012

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.

@danielpalme
Copy link
Contributor

It's no problem to integrate and extend the patch.
But first I want to understand why excluded classes/methods/properties are not excluded in the coverage report. That seems to make more sense than marking them as excluded?
Edit:
I tried the attribute on classes, methods and properties. But the report only contains the 'skippedDueTo' attribute on class level. What about methods and properties?

@sawilde
Copy link
Member Author

sawilde commented Jan 22, 2012

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.

@danielpalme
Copy link
Contributor

Hi Shaun

I tested with the following class:

public class ClassWithExcludes
{
    public string IncludedProperty { get; set; }

    [CoverageExclude]
    public string ExcludedProperty { get; set; }

    public void IncludedMethod()
    {
        this.IncludedProperty = "Test";
    }

    [CoverageExclude]
    public void ExcludedMethod()
    {
        this.ExcludedProperty = "Test";
    }
}

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.
Am I doing something wrong?

@sawilde sawilde reopened this Jan 22, 2012
@sawilde
Copy link
Member Author

sawilde commented Jan 22, 2012

Thanks - I seem to have broken it by filtering the method out somewhere else - code is updated

@danielpalme
Copy link
Contributor

Great. I will add the filtering to ReportGenerator soon.

@danielpalme
Copy link
Contributor

I just tested with the latest changes. The excluded method now has the "skippedDueTo" attribute.
What about the excluded property, it is not marked with the attribute?!

@sawilde
Copy link
Member Author

sawilde commented Jan 23, 2012

Looks like a bug - currently I think it works if you set it directly against the get; and set; i.e.

public string XYZ
{
[Exclude]
get;
[Exclude]
set;
}

I need to work out why this is

@danielpalme
Copy link
Contributor

I just published ReportGenerator 1.2.5.0. It now handles excludes on all levels (module, class, method/property).
Download: http://reportgenerator.codeplex.com

sawilde added a commit that referenced this issue Jan 25, 2012
@sawilde
Copy link
Member Author

sawilde commented Jan 25, 2012

I hope this issue is now complete with 2.1.25 - if not we should create a new issue as this one was hijacked.

@sawilde sawilde closed this as completed Jan 25, 2012
@SteveDunn
Copy link

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 internal. I then add this as a linked file in the projects that need them.

@sawilde
Copy link
Member Author

sawilde commented Mar 27, 2012

Okay thanks for that I'll update the documentation to inform people that

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants