Skip to content

Commit bf25e4f

Browse files
authored
Merge pull request #254 from tonyhallett/readme-for-fcc-options
Readme for fcc options
2 parents ef60caf + 6b21997 commit bf25e4f

File tree

5 files changed

+224
-21
lines changed

5 files changed

+224
-21
lines changed

Art/Options-Global.png

18 KB
Loading

FineCodeCoverageTests/CoverageProject_Settings_Tests.cs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public void Should_Overwrite_String_Array_By_Default()
258258
var mockAppOptions = new Mock<IAppOptions>();
259259
mockAppOptions.SetupAllProperties();
260260
var appOptions = mockAppOptions.Object;
261-
261+
appOptions.Exclude = new string[] { "global" };
262262
var stringArrayElement = XElement.Parse($@"
263263
<Root>
264264
<Exclude>
@@ -278,6 +278,84 @@ public void Should_Overwrite_String_Array_By_Default()
278278
Assert.AreEqual(new string[] { "1", "2"}, appOptions.Exclude);
279279
}
280280

281+
[Test]
282+
public void Should_Overwrite_String_Array_DefaultMerge_False()
283+
{
284+
var mockAppOptions = new Mock<IAppOptions>();
285+
mockAppOptions.SetupAllProperties();
286+
var appOptions = mockAppOptions.Object;
287+
appOptions.Exclude = new string[] { "global" };
288+
var stringArrayElement = XElement.Parse($@"
289+
<Root defaultMerge='false'>
290+
<Exclude>
291+
1
292+
2
293+
</Exclude>
294+
</Root>
295+
");
296+
297+
var settingsMerger = new SettingsMerger(null);
298+
var mergedSettings = settingsMerger.Merge(
299+
appOptions,
300+
new List<XElement> { },
301+
stringArrayElement);
302+
303+
Assert.AreSame(appOptions, mergedSettings);
304+
Assert.AreEqual(new string[] { "1", "2" }, appOptions.Exclude);
305+
}
306+
307+
[Test]
308+
public void Should_Overwrite_String_Array_DefaultMerge_True_Property_Merge_false()
309+
{
310+
var mockAppOptions = new Mock<IAppOptions>();
311+
mockAppOptions.SetupAllProperties();
312+
var appOptions = mockAppOptions.Object;
313+
appOptions.Exclude = new string[] { "global" };
314+
var stringArrayElement = XElement.Parse($@"
315+
<Root defaultMerge='true'>
316+
<Exclude merge='false'>
317+
1
318+
2
319+
</Exclude>
320+
</Root>
321+
");
322+
323+
var settingsMerger = new SettingsMerger(null);
324+
var mergedSettings = settingsMerger.Merge(
325+
appOptions,
326+
new List<XElement> { },
327+
stringArrayElement);
328+
329+
Assert.AreSame(appOptions, mergedSettings);
330+
Assert.AreEqual(new string[] { "1", "2" }, appOptions.Exclude);
331+
}
332+
333+
[Test]
334+
public void Should_Overwrite_String_Array_DefaultMerge_Not_Bool()
335+
{
336+
var mockAppOptions = new Mock<IAppOptions>();
337+
mockAppOptions.SetupAllProperties();
338+
var appOptions = mockAppOptions.Object;
339+
appOptions.Exclude = new string[] { "global" };
340+
var stringArrayElement = XElement.Parse($@"
341+
<Root defaultMerge='xxx'>
342+
<Exclude>
343+
1
344+
2
345+
</Exclude>
346+
</Root>
347+
");
348+
349+
var settingsMerger = new SettingsMerger(null);
350+
var mergedSettings = settingsMerger.Merge(
351+
appOptions,
352+
new List<XElement> { },
353+
stringArrayElement);
354+
355+
Assert.AreSame(appOptions, mergedSettings);
356+
Assert.AreEqual(new string[] { "1", "2" }, appOptions.Exclude);
357+
}
358+
281359
[Test]
282360
public void Should_Merge_String_Array_If_DefaultMerge()
283361
{
@@ -312,7 +390,7 @@ public void Should_Merge_If_Property_Element_Merge()
312390
var appOptions = mockAppOptions.Object;
313391
appOptions.Exclude = new string[] { "global" };
314392
var stringArrayElement = XElement.Parse($@"
315-
<Root>
393+
<Root defaultMerge='false'>
316394
<Exclude merge='true'>
317395
1
318396
2

FineCodeCoverageTests/CoverletDataCollectorUtil_CanUseDataCollector_Tests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using FineCodeCoverage.Core.Utilities;
66
using FineCodeCoverage.Engine.Coverlet;
77
using FineCodeCoverage.Engine.Model;
8+
using FineCodeCoverageTests.Test_helpers;
89
using Moq;
910
using NUnit.Framework;
1011

@@ -22,6 +23,7 @@ public void SetUp()
2223
{
2324
mocker = new AutoMoqer();
2425
coverletDataCollectorUtil = mocker.Create<CoverletDataCollectorUtil>();
26+
coverletDataCollectorUtil.ThreadHelper = new TestThreadHelper();
2527
}
2628

2729
private void SetUpRunSettings(Mock<ICoverageProject> mockCoverageProject, Action<Mock<IRunSettingsCoverletConfiguration>> setup)
@@ -118,6 +120,45 @@ public void Should_Use_Data_Collector_If_Not_Specified_In_RunSettings_And_Specif
118120
Assert.True(coverletDataCollectorUtil.CanUseDataCollector(mockCoverageProject.Object));
119121
}
120122

123+
[TestCase(UseDataCollectorElement.True, true)]
124+
[TestCase(UseDataCollectorElement.Empty, true)]
125+
[TestCase(UseDataCollectorElement.False, false)]
126+
[TestCase(UseDataCollectorElement.None, false)]
127+
public void Should_Use_Data_Collector_If_Not_Specified_In_RunSettings_And_Specified_In_ProjectFile_VSBuild(UseDataCollectorElement useDataCollector, bool expected)
128+
{
129+
var mockCoverageProject = new Mock<ICoverageProject>();
130+
var guid = Guid.NewGuid();
131+
mockCoverageProject.Setup(cp => cp.Id).Returns(guid);
132+
mockCoverageProject.Setup(cp => cp.ProjectFileXElement).Returns(new XElement("Root"));
133+
134+
135+
var mockVsBuildFCCSettingsProvider = mocker.GetMock<IVsBuildFCCSettingsProvider>();
136+
var useDataCollectorElement = "";
137+
if (useDataCollector != UseDataCollectorElement.None)
138+
{
139+
var value = "";
140+
if (useDataCollector == UseDataCollectorElement.True)
141+
{
142+
value = "true";
143+
}
144+
if (useDataCollector == UseDataCollectorElement.False)
145+
{
146+
value = "false";
147+
}
148+
useDataCollectorElement = $"<UseDataCollector>{value}</UseDataCollector>";
149+
}
150+
XElement vsBuildProjectFileElement = XElement.Parse($"<FineCodeCoverage>{useDataCollectorElement}</FineCodeCoverage>");
151+
mockVsBuildFCCSettingsProvider.Setup(
152+
vsBuildFCCSettingsProvider =>
153+
vsBuildFCCSettingsProvider.GetSettingsAsync(guid)
154+
).ReturnsAsync(vsBuildProjectFileElement);
155+
156+
157+
158+
159+
Assert.AreEqual(expected,coverletDataCollectorUtil.CanUseDataCollector(mockCoverageProject.Object));
160+
}
161+
121162
[Test]
122163
public void Should_Use_Data_Collector_If_No_RunSettings_And_Specified_In_ProjectFile()
123164
{

README.md

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ or download from [releases](https://github.com/FortuneN/FineCodeCoverage/release
88
---
99
## Prerequisites
1010

11-
Only that the test adapters are nuget packages. For instance, the NUnit Test Adapter extension is not sufficient.
12-
11+
For .Net - that the test adapters are nuget packages. For instance, the NUnit Test Adapter extension is not sufficient.
1312

1413
---
1514

@@ -21,10 +20,10 @@ tool for most developers. It is currently in Beta.
2120

2221
With the old coverage it was possible for FCC to provide an abstraction over each tool's exclusion / inclusion options. This abstraction does not work for MS code coverage.
2322
Thus you will find that there are separate configuration options for Ms coverage vs old coverage and options that are common to the two.
24-
Configuration is available with Visual Studio options and project msbuild properties. All visual studio settings can be overridden from test project settings and some settings
25-
can only be set in project files.
23+
Configuration is ( mostly ) determined from Visual Studio options, finecodecoverage-settings.xml files and project msbuild properties. All of these settings are optional.
24+
For options that have a project scope, these settings form a hierarchy where lower levels override or, for collections, override or merge with the level above. This is described in detail further on.
2625

27-
Regardless of the coverage tool employed the process begins with FCC reacting to the test explorer in visual studio. One of the 3 coverage tools provides the coverage results that are presented as a single unified report in the Fine Code Coverage Tool Window. The report shows line and branch coverage and risk hotspots with the facility to open your class files that will have coloured margins to indicate uncovered or partially covered code.
26+
Regardless of the coverage tool employed the process begins with FCC reacting to the test explorer in visual studio. One of the 3 coverage tools provides the coverage results that are presented as a single unified report in the Fine Code Coverage Tool Window. The report shows line and branch coverage and risk hotspots with the facility to open your class files, that will have coloured margins to indicate uncovered or partially covered code.
2827
This coverage is not dynamic and represents the coverage obtained from the last time you executed tests. When the coverage becomes outdated, you can click the 'FCC Clear UI' button in Tools or run coverage again.
2928

3029
Details of how FCC is progressing with code coverage can be found in the Coverage Log tab in the Fine Code Coverage Tool Window with more detailed logs in the FCC Output Window Pane. If you experience issues then providing the logs from the output window will help to understand the nature of the problem.
@@ -35,6 +34,8 @@ With the old coverage FCC needed to copy your test dll and dependencies and run
3534
The old coverage would wait until tests have finished before starting the coverage tool to re-run all tests. This is not necessary with ms code coverage.
3635
The old coverage was based upon every test. Ms code coverage is coverage from the tests you select in the test explorer.
3736

37+
**Supports C++ !** Note that FCC has not been properly tested with C++ projects but with a simple C++ class, tested with Google Test, FCC provides coverage.
38+
3839
## How to utilize MS Code Coverage with FCC ?
3940

4041
Firstly you need to change the RunMsCodeCoverage option from No.
@@ -48,11 +49,11 @@ FCC does not require you to do this. If you do not provide a runsettings and Ru
4849
## Run settings generation from template
4950

5051
FCC includes the ms code coverage package and will create the necessary runsettings file for each test project being run from the test explorer window.
51-
The exclusions and inclusions will come from visual studio options or from the project file in a similar manner to the old coverage. As ms code coverage uses regex and has different methods of exclusion / inclusion to
52-
Coverlet and OpenCover there are ms specific Visual Studio options and project elements.
52+
The exclusions and inclusions will come from the combined settings, in a similar manner to the old coverage. As ms code coverage uses regex and has different methods of exclusion / inclusion to
53+
Coverlet and OpenCover there are ms specific Visual Studio options and associated elements.
5354

5455
As FCC provides a runsettings file for each test project ( if you have not provided a solution wide or project specific ) it has to write the RunSettingsFilePath element in the project file.
55-
Although FCC removes this element from the project file it will still show as git modified.
56+
Although FCC clears the value of this element from the project file it is still present.
5657

5758
FCC creates the runsettings from a template using string replacement. If so desired you can provide your own templates. FCC will look for fcc-ms-runsettings-template.xml in the project directory or the solution directory.
5859
Your template needs to be a valid xml document but does not need to supply all of the run settings elements. FCC will add the replaceable ResultsDirectory and TestAdaptersPaths ( and the container RunConfiguration element if necessary)
@@ -108,10 +109,42 @@ Run a(some) unit test(s) and ...
108109
#### See Risk Hotspots View
109110
![Risk Hotspots View](Art/Output-RiskHotspots.png)
110111

111-
#### Global (Shared) options
112+
## Project configuration
113+
114+
The hierarchy is as follows :
115+
116+
a) Visual Studio options
117+
112118
![Global Options](Art/Options-Global.png)
113119

114-
#### Local (Test Project) options (override globals in your csproj/vbproj : OPTIONAL)
120+
121+
b) finecodecoverage-settings.xml files
122+
123+
These are found by walking up the directory structure from the project directory.
124+
By applying the attribute topLevel='true' to the root element the walk stops.
125+
126+
Given finecodecoverage-settings.xml in project directory and finecodecoverage-settings.xml in the solution directory the
127+
hierachy is :
128+
129+
Visual Studio options
130+
131+
Solution level finecodecoverage-settings.xml
132+
133+
Project level finecodecoverage-settings.xml
134+
135+
```
136+
<FineCodeCoverage>
137+
<Enabled>
138+
True
139+
</Enabled>
140+
<!-- and more -->
141+
</FineCodeCoverage>
142+
```
143+
144+
c) msbuild project file
145+
146+
There are two ways of supplying these settings.
147+
Directly in the project file
115148
```
116149
<PropertyGroup Label="FineCodeCoverage">
117150
<Enabled>
@@ -140,7 +173,8 @@ Run a(some) unit test(s) and ...
140173
<!-- and more -->
141174
</PropertyGroup>
142175
```
143-
or **( necessary if storing project settings outside your project file and using msbuild Import )**
176+
177+
With the FineCodeCoverage element.
144178
```
145179
<PropertyGroup>
146180
<FineCodeCoverage>
@@ -151,6 +185,18 @@ or **( necessary if storing project settings outside your project file and using
151185
</FineCodeCoverage>
152186
</PropertyGroup>
153187
```
188+
This is **necessary** if storing project settings outside your project file and using msbuild Import.
189+
190+
It is also **necessary if** you want to have the setting element merge with that from the level above as msbuild does not
191+
support custom attributes.
192+
193+
### Controlling merge
194+
195+
The default is to overwrite each collection property. This can be changed for all settings by setting defaultMerge='true' on the root element.
196+
197+
If you do supply the merge attribute on a setting element then it will be used.
198+
199+
### Project only
154200

155201
#### Exclude Referenced Project in referenced project ( csproj/vbproj : OPTIONAL )
156202
```

0 commit comments

Comments
 (0)