Welcome, Guest!

Icon for NCOVER

Icon for NCOVER

by forums on Tuesday September 18, 2007, 01:33 PM

On the next version of NCOVER, why not add the very nice looking icon on the website to NCover.Console.exe?

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

My log file appears to have a "match" line for every class I applied the attribute to, like below:

MESSAGE: Found Attribute [BusinessLayer.NCoverIgnoreAttribute], Excluding Item from Coverage
MESSAGE: Class Excluded

However, they still show up in the coverage report.

Hope this helps track it down.

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

Same situation, but executed method with Skip attribute...

using System;
using NUnit.Framework;

[AttributeUsage(AttributeTargets.All)]
class SkipAttribute : Attribute {}

[TestFixture]
public class Class1
{
    void Method1(){}            // executed, 100% coverage, Ok
    [Skip]void Method2(){}   // not executed, 0% coverage
    [Skip]void Method3(){}   // executed, but 0% coverage
    
    [Test]public void Test1()
    {
        Method1();
        Method3();
    }
}

command:
"c:\Program Files\NCover\NCover.Console.exe" "c:\Program Files\NUnit 2.2.6\bin\nunit-console.exe" ClassLibrary1.dll //a ClassLibrary1 //w "ClassLibrary1\bin\Debug" //ea SkipAttribute

Coverage.Log:
...
MESSAGE: Monitoring Assemblies: ClassLibrary1;
MESSAGE: Excluding Types and Methods with these Attributes: SkipAttribute;
...

Coverage.Xml:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="coverage.xsl" type="text/xsl"?>
<!-- saved from url=(0022)http://www.ncover.org/ -->
<coverage>
  <module name="c:\windows\temp\nunit20\shadowcopycache\632745970413593750\tests\assembly\dl2\fe141f69\ae08dc7e_da28c601\classlibrary1.dll" assembly="ClassLibrary1">
    <method name="Method1" class="Class1">
      <seqpnt visitcount="1" line="10" column="17" endline="10" endcolumn="18" document="d:\classlibrary1\classlibrary1\class1.cs" />
    </method>
    <method name="Method2" class="Class1">
      <seqpnt visitcount="0" line="11" column="23" endline="11" endcolumn="24" document="d:\classlibrary1\classlibrary1\class1.cs" />
    </method>
    <method name="Method3" class="Class1">
      <seqpnt visitcount="0" line="12" column="23" endline="12" endcolumn="24" document="d:\classlibrary1\classlibrary1\class1.cs" />
    </method>
    <method name="Test1" class="Class1">
      <seqpnt visitcount="1" line="16" column="3" endline="16" endcolumn="13" document="d:\classlibrary1\classlibrary1\class1.cs" />
      <seqpnt visitcount="1" line="17" column="3" endline="17" endcolumn="13" document="d:\classlibrary1\classlibrary1\class1.cs" />
      <seqpnt visitcount="1" line="18" column="2" endline="18" endcolumn="3" document="d:\classlibrary1\classlibrary1\class1.cs" />
    </method>
  </module>
</coverage>


Hope this helps track it down.

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

I found that if I specify the "simple" name for the method-level attribute (Test instead of NUnit.Framework.TestAttribute) that it does change the behavior, but not in the way that I had hoped. 
The marked functions remain in the report, but are considered uncovered.  My 65% coverage drops to 35% coverage, as every line of my unit tests is now considered uncovered, rather than being ignored completely.

Also, specifying a class-level attribute (TestFixture or NUnit.Framework.TestFixtureAttribute) seems to have no effect on the output.

Hopefully this is of use to someone in tracking down the bug. I'm very much looking forward to rolling out 1.5.x to our build system when this feature works.

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

<font>I'm having this same problem.

I've checked the following:
</font>

  • <font>The //ea is spelled correctly</font>
  • <font>The class indeed has the attribute.</font>
  • <font>The log file shows that the attribute class is being picked up. I see the following in the log
    </font>
  • <font>MESSAGE: Excluding Types and Methods with these Attributes: my.CoverageExcludeAttribute;
    </font>
<font>Is there anything else to check for?

By the way, great product!

Richard
</font>

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

To all of you,


Great feedback.  Looking into it now...

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

i want the syntax for using the //ea attribute. i have tried a lot of ways but couldn't get through it.

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

The syntax is just "//ea FullNamespaceClassName" - e.g. if you define an attribute "BarAttribute" in the "Foo" namespace, then it should be just:


<font>ncover.console //ea Foo.BarAttribute ...</font>


The easiest way we found of handling this was defining in  our AssemblyInfo.cs (or in a CommonAssemblyInfo.cs which you link across projects) the following line:


<font>internal sealed class CoverageExcludeAttribute : System.Attribute {}</font>


That means anywhere in the .dll we can mark classes or methods with [CoverageExclude], do not have to add "using" statements throughout the code, and the command-line is simply:


<font>ncover.console //ea CoverageExcludeAttribute ...</font>


Even better, Jamie Cansdale has built in default support for an attribute named exactly this way into TestDriven.Net, so when you choose "Test with... Coverage" it will automatically apply a "//ea CoverageExcludeAttribute" argument, for when you view the results in NCoverExplorer.


One final point - there are some known problems with the coverage exclusion feature not always working correctly (as of 1.5.4) as mentioned in other threads. I believe these have been fixed by Peter to be included in the next NCover release.


Hope this helps,
Grant.
http://www.kiwidude.com/blog/


 

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

has any had any luck with getting the //ea to work?


I've added it to mine with the full namespace of the class i'm wanting to exclude. According to the NCover log, it reconises that it need to be exlucluded, but nothing different happens.

Re: 1.5.2 exclusion feature

by forums on Tuesday September 18, 2007, 01:33 PM

Well, as per the above post, yes it should work.


Just from your comment above - you do realise you have to define an attribute and put that on the class you want to exclude and put the namespace for that attribute name in the //ea arguments i.e. not the name of the class you are excluding itself?


i.e. define an attribute:

<font>internal sealed class CoverageExcludeAttribute : System.Attribute {}</font>


Apply it to your class or methods:


<font>[CoverageExclude]
public class SomeClassIWantToHide
{
   ...
}</font>

<font>

Then pass the name of that attribute in the //ea arguments...


<font>ncover.console //ea CoverageExcludeAttribute ...</font>

</font>

Re: 1.5.2 exclusion feature, multiple exclusion

by forums on Tuesday September 18, 2007, 01:33 PM

<font>Hi,</font>


<font>is it possible to exclude multiple attributes.  When writing WPF apps, you get two candidates that you want to ignore for sure in addition to CoverageExcludeAttribute:</font>

<font>

<font><font>System.Diagnostics.DebuggerNonUserCodeAttribute
<font>System.Runtime.CompilerServices.CompilerGeneratedAttribute</font></font></font>


<font>I have tried using //ea twice, but that does not work.  Is there a magic delimiter like , or ; ?  Does multiple exclusion work at all?</font>


<font><font>Friedrich Brunzema</font></font>

</font>

Re: 1.5.2 exclusion feature, multiple exclusion

by forums on Tuesday September 18, 2007, 01:33 PM

Hi,


I hate answring my own questions; should have tried it right away.  The magical delimiter is the semicolon, and things seem to exclude OK in version 1.5.5

<font>
//ea System.Diagnostics.DebuggerNonUserCodeAttribute;System.Runtime.CompilerServices.CompilerGeneratedAttribute


F.

</font>

Re: Can't get Coverage File output

by forums on Tuesday September 18, 2007, 01:34 PM

Assemblies should be just the name, not the path (i.e. <Assemblies>Common</Assemblies>)

Re: Can't get Coverage File output

by forums on Tuesday September 18, 2007, 01:34 PM

Hi Peter,

I tried your suggestion but it's still not working.  I still only get the NCover log file but no coverage file (CommonTests.NCover.xml).

Any other ideas?

Cheers,
r/

Re: Can't get Coverage File output

by forums on Tuesday September 18, 2007, 01:34 PM

peterwald wrote:
Assemblies should be just the name, not the path (i.e. <Assemblies>Common</Assemblies>)


Could you explain what the difference is between the assemblies passed in to the <font>commandLineArgs</font>, and those listed in <font>assemblies</font>. Which is equivalent to the <font>//a</font> parameter that gets passed in to <font>ncover.console.exe</font>?

For instance, in my old build file, I had this code:
        <exec    program="${ncover.exe}" 
                workingdir="${output.dir}">
            <!-- This argument is for NCover, telling it which process to monitor for coverage -->
            <arg value="${nunit.exe}" />
            <!-- This argument is for NUnit, telling it which assembly to search for fixtures -->
            <arg value="/xml:${output.dir}\nunit-results.xml ${build.dir}\mytest.dll /nologo" />
            <!-- This argument is for NCover, so send it verbatim -->
            <arg line="//a My.Namespace.To.Test" />
        </exec>

How would that translate into the new <font><ncover></font> task?