Using TC 9.1.3, how to call dotCover from nunitlauncher with parameters ?

I've setup a MSBuild file with several targets.

In one of the target I am calling
        <Exec Command="$(teamcity_dotnet_nunitlauncher) v4.0 X86 NUnit-2.5.9 @(UnitTestDlls)"/>

where @(UnitTestDlls) is a group of items containing the DLL I want to unit tests. I do it this way since from the web interface I cannot dynamically build a list of DLL to unit test.

Anyway, this is working fine but now I would like to add coverage analysis with DotCover.

In the past we used PartCover as follows:
        <Exec Command="$(teamcity_dotnet_nunitlauncher) v4.0 X86 NUnit-2.5.9 @(UnitTestDlls) /partcover:%22$(PartCoverConsole)%22 /partcover-arguments:%22--register --output $(PartCoverXmlOutputFile) --include [*]* --exclude [Accessibility]* --exclude [*]Microsoft* --exclude [*test*]* --exclude [*Test*]* --exclude [*JetBrains*]* --exclude [*nunit*]* --exclude [*log4net*]* --exclude [*CookComputing*]* @(ExternalLibraries-&gt;'--exclude [%(Filename)]* ','')%22"/>

and it was working great.

I tried changing the /partcover argument to /dotcover but it would seem that the launcher does not support arguments for dotcover !

Please advise.

Thank you

9 comments
Comment actions Permalink

Hi, Stecy Dube

Please see following document https://confluence.jetbrains.com/display/TCD9/NUnit+for+MSBuild

I advise you to replace the tag:

<Exec Command="$(teamcity_dotnet_nunitlauncher) v4.0 X86 NUnit-2.5.9 @(UnitTestDlls)"/>


for the tag:

<NUnit Assemblies="@(UnitTestDlls)"/>


Use "MSBuild" build step with the predefined field ".NET Coverage tool". Just set to "JetBrains dotCover"

0
Comment actions Permalink

How do I supply exclusions for some dlls using the msbuild task ?

0
Comment actions Permalink

Hi, Stecy Dube
As I understand you want to filter some assemblies from target outputs.
You could do it directly in the .proj file. For simple scenario see this sample:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
               <UsingTask TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" />

     <Target Name="Build">     
          <MSBuild Projects="C:\Projects\TestSolution\UnitTestProject1\UnitTestProject1.csproj">
               <Output TaskParameter="TargetOutputs" ItemName="Assemblies" />
          </MSBuild>

          <MSBuild Projects="C:\Projects\TestSolution\UnitTestProject2\UnitTestProject2.csproj">
               <Output TaskParameter="TargetOutputs" ItemName="Assemblies" />
          </MSBuild>

          <MSBuild Projects="C:\Projects\TestSolution\UnitTestProject3\UnitTestProject3.csproj">
               <Output TaskParameter="TargetOutputs" ItemName="Assemblies" />
          </MSBuild>

          <CreateItem Include="$(MSBuildStartupDirectory)\**\UnitTestProject*.csproj">
                  <Output ItemName="NUnitAssemblies" />
                                <CreateItem>

          <Message Text="Assemblies for NUnit: @(NUnitAssemblies)" Importance="high"/>

          <NUnit Assemblies="@(NUnitAssemblies)" ToolPath="packages\NUnit.Runners.2.6.4\tools\"/>
     </Target>
</Project>


If you would like to filter files by the some regular expression you could use following sample:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     <UsingTask TaskName="GetNUnitAssemblies" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
          <ParameterGroup>
               <assemblies ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
               <filter ParameterType="System.String" Required="true" />
               <nunitAssemblies ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true"/>
          </ParameterGroup>
          <Task>
               <Using Namespace="System"/>
               <Using Namespace="System.Linq"/>
               <Using Namespace="System.Text.RegularExpressions"/>
                                <Code Type="Fragment" Language="cs">
               <![CDATA[               
               Regex reg = new Regex(filter);
               nunitAssemblies = (from assembly in assemblies where reg.IsMatch(assembly.ItemSpec) select assembly).ToArray();
               ]]>
                                </Code>
              </Task>
     </UsingTask>

                <UsingTask TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" />


     <Target Name="Build">     
          <MSBuild Projects="C:\Projects\TestSolution\UnitTestProject1\UnitTestProject1.csproj">
               <Output TaskParameter="TargetOutputs" ItemName="Assemblies" />
          </MSBuild>

          <MSBuild Projects="C:\Projects\TestSolution\UnitTestProject2\UnitTestProject2.csproj">
               <Output TaskParameter="TargetOutputs" ItemName="Assemblies" />
          </MSBuild>

          <MSBuild Projects="C:\Projects\TestSolution\UnitTestProject3\UnitTestProject3.csproj">
               <Output TaskParameter="TargetOutputs" ItemName="Assemblies" />
          </MSBuild>

          <GetNUnitAssemblies assemblies="@(Assemblies)" filter="UnitTestProject[13]">
               <Output TaskParameter="NUnitAssemblies" ItemName="nunitAssemblies" />
          </GetNUnitAssemblies>

          <Message Text="Assemblies for NUnit: @(NUnitAssemblies)" Importance="high"/>

          <NUnit Assemblies="@(NUnitAssemblies)" ToolPath="packages\NUnit.Runners.2.6.4\tools\"/>
     </Target>
</Project>


I've attached solution with samples



Attachment(s):
TestSolution.zip
0
Comment actions Permalink

Thank you for replying,

however I still see coverage for the test assemblies themselves and I would rather not see them.


As as example, suppose I have the following:

  • AssemblyTests.dll
    • Assembly.dll
      • SomeOtherAssembly.dll
    • NUnitFramework.dll


I only want coverage report to show the coverage for Assembly.dll and nothing else.

0
Comment actions Permalink

If you use "MSBuild" build step you can define "Assemblies Filters" via TaemCity UI

0
Comment actions Permalink

Yes, I know but I cannot do it dynamically from the teamcity UI.

I don't want to modify all the time the filters from the UI when a new assembly is added.
I would prefer to be able to have a way to supply an exclude parameter from MSBuild consisting of dynamically built items like so:

     <CreateItem Include="lib\**\*.dll">
          <Output TaskParameter="Include" ItemName="ExternalLibraries"/>
     </CreateItem>

     <NUnit Assemblies="@(UnitTestDlls)" NUnitVersion="NUnit-2.6.3" RunProcessPerAssembly="True" Filters="@(ExternalLibraries-&gt;'-:%(Filename)','')"/>

This way I could exclude all assemblies from my lib folder (3rd party assemblies and internal assemblies).

0
Comment actions Permalink

Hi, Stecy Dube

There is no way to configure filters for the dotCover using the NUnit Launcher's arguments. Can you separate your project on the two step? The first step builds projects, creates the list of testing assemblies and creates the filter for the dotCover. The second step runs test.

0
Comment actions Permalink

I sure can separate the two steps but I fail to see how it would help defining the exclusions dynamically.

0
Comment actions Permalink

- Add a configuration parameter (Build Configuration Settings\Parameters) -> Add new parameter: name = "myFilter", kind = "Configuration parameter", Value = ""
- Use a console output to configure this configuration parameter from some build step. For example from the cmd line:

echo ##teamcity[setParameter name='myFilter' value='-:HelloWorld.Tests']

- Specify the "Filters:" field as %myFilter% in the build step for tests under the dotCover

0

Please sign in to leave a comment.