MSBuild task for automating NCoverExplorer.Console. Using this task you can merge coverage files from NCover, produce xml coverage reports for use with CruiseControl.Net, produce html report files directly, fail automated builds if coverage thresholds are not met and apply a range of detail to the reports produced such as sorting, filtering and coverage exclusions.
For a list of all members of this type, see NCoverExplorer Members.
System.Object
Task
ToolTask
NCoverExplorer
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
This example shows producing an xml coverage report at Module/Namespace/Class detail level for inclusion on a CC.Net build server. You would add a merge file task in the publishers section of your CC.Net project file to merge in this "CoverageSummary.xml" file so that it can be transformed by the NCoverExplorer xsl stylesheets you have copied into the CC.Net folder. Here we have set a satisfactory coverage threshold at 80%.
<ItemGroup> <CoverageFile Include="$(MSBuildProjectDirectory)\Coverage\Coverage.xml" /> </ItemGroup> <NCoverExplorer ToolPath="Tools\NCoverExplorer\" ProjectName="My Project" OutputDir="$(MSBuildProjectDirectory)\Coverage" CoverageFiles="@(CoverageFile)" SatisfactoryCoverage="80" ReportType="4" XmlReportName="CoverageSummary.xml" />This example shows producing an html function coverage report, excluding the test assemblies. The assemblies excluded are being displayed at the bottom of the report. Note also that this time the ReportType is specified by its enum name rather than numeric value - they are interchangable. We have also "inlined" the "CoverageFiles" from the ItemGroup above to show this can be done.
<PropertyGroup> <CoverageExclusions> <CoverageExclusion ExclusionType="Assembly" Pattern="*.Tests" /> </CoverageExclusions> </PropertyGroup> <NCoverExplorer ToolPath="Tools\NCoverExplorer\" ProjectName="My Project" OutputDir="$(MSBuildProjectDirectory)\Coverage" CoverageFiles="$(MSBuildProjectDirectory)\Coverage\Coverage.xml" SatisfactoryCoverage="80" ReportType="ModuleClassFunctionSummary" HtmlReportName="CoverageSummary.html" Exclusions="$(CoverageExclusions)" ShowExcluded="True" />This example shows producing an html module class summary coverage report with exclusions as above. This time we have added applying specific sorting and filtering criteria. This report will show all classes that do not have 100% coverage, sorted within their namespaces by descending coverage %. We have also "inlined" the exclusions
<NCoverExplorer ToolPath="Tools\NCoverExplorer\" ProjectName="My Project" OutputDir="$(MSBuildProjectDirectory)\Coverage" CoverageFiles="$(MSBuildProjectDirectory)\Coverage\Coverage.xml" SatisfactoryCoverage="80" ReportType="ModuleClassSummary" HtmlReportName="CoverageSummary.html" Exclusions="Assembly=*.Tests;" ShowExcluded="True" Sort="CoveragePercentageDescending" Filter="HideFullyCovered" />This example shows the merging capability to produce a consolidated merge file from multiple coverage test runs. The results are being stored in a single "MyApp.CoverageMerged.xml" file. Note that you could additionally apply coverage exclusions at this point. Merging files can be useful if your testing process requires multiple coverage runs and you want a single archive which consolidates the results.
<ItemGroup> <CoverageFile Include="$(MSBuildProjectDirectory)\Coverage\MyApp*.Coverage.xml" /> </ItemGroup> <NCoverExplorer ToolPath="Tools\NCoverExplorer\" OutputDir="$(MSBuildProjectDirectory)\Coverage" ReportType="None" CoverageFiles="@(CoverageFile)" MergeFileName="MyApp.CoverageMerged.xml" />This example shows failing a build if the overall coverage % does not meet our threshold, without producing a coverage report.
<NCoverExplorer ToolPath="Tools\NCoverExplorer\" ProjectName="My Project" ReportType="None" CoverageFiles="$(MSBuildProjectDirectory)\Coverage\Coverage.xml" SatisfactoryCoverage="80" FailMinimum="True" />This example shows failing a build if either the overall coverage % does not meet our threshold, or if one of the individual module thresholds is not met. Note that the ModuleThresholds could have been "inlined" (just showing the MSBuild flexibility to place in a separate group).
<ItemGroup> <ModuleThreshold Include="MyProject.1.dll=75" /> <ModuleThreshold Include="MyProject.2.dll=85" /> </ItemGroup> <NCoverExplorer ToolPath="Tools\NCoverExplorer\" ProjectName="My Project" ReportType="None" CoverageFiles="$(MSBuildProjectDirectory)\Coverage\Coverage.xml" SatisfactoryCoverage="80" FailMinimum="True" ModuleThresholds="@(ModuleThreshold)" />This example shows using virtually the whole range of attributes. Shown below is failing a build if not reaching the overall or module level coverage thresholds. The results of merging multiple NCover files together are stored as a separate file. We are producing xml and html Namespace per module summary reports (with the exclusions show in the footer). Note that the module thresholds will also be used in the reports. The reports are sorted by name with no filter applied. We are excluding test assemblies and anything in a presentation layer namespace.
<ItemGroup> <CoverageFile Include="$(MSBuildProjectDirectory)\Test\Coverage\*.Coverage.xml" /> </ItemGroup> <PropertyGroup> <CoverageExclusions> <CoverageExclusion ExclusionType="Class" Pattern="MyApp.SomeNamespace.SomeClass" /> <CoverageExclusion ExclusionType="Namespace" Pattern="MyApp\.(\w*\.)?" IsRegex="true" /> </CoverageExclusions> </PropertyGroup> <NCoverExplorer ToolPath="Tools\NCoverExplorer\" ProjectName="My Project" ReportType="ModuleNamespaceSummary" Sort="Name" Filter="None" OutputDir="$(MSBuildProjectDirectory)\Test\Coverage" XmlReportName="CoverageSummary.xml" HtmlReportName="CoverageSummary.html" MergeFileName="CoverageMerge.xml" ShowExcluded="True" SatisfactoryCoverage="80" FailMinimum="True" CoverageFiles="@(CoverageFile)" Exclusions="$(CoverageExclusions)" ModuleThresholds="MyProject.1.dll=75;MyProject.2.dll=85" />
Namespace: NCoverExplorer.MSBuildTasks
Assembly: NCoverExplorer.MSBuildTasks (in NCoverExplorer.MSBuildTasks.dll)
NCoverExplorer Members | NCoverExplorer.MSBuildTasks Namespace