Skip to content

Commit 9733b47

Browse files
authored
Merge pull request #501 from tonyhallett/tunit
working tunit - perhaps the manifest install targets should have been updated......
2 parents 9730d20 + 8d21357 commit 9733b47

File tree

56 files changed

+2752
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2752
-44
lines changed

FineCodeCoverage/FineCodeCoverage.csproj

+19
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
<Link>ZippedTools\coverlet.console.6.0.4.zip</Link>
126126
<IncludeInVSIX>true</IncludeInVSIX>
127127
</Content>
128+
<Content Include="..\Shared Files\ZippedTools\dotnet-coverage.17.14.2.zip">
129+
<Link>ZippedTools\dotnet-coverage.17.14.2.zip</Link>
130+
<IncludeInVSIX>true</IncludeInVSIX>
131+
</Content>
128132
<!--
129133
<None Include="Key.snk" />
130134
-->
@@ -165,6 +169,9 @@
165169
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild">
166170
<Version>3.11.0</Version>
167171
</PackageReference>
172+
<PackageReference Include="Microsoft.ServiceHub.Framework">
173+
<Version>3.1.4097</Version>
174+
</PackageReference>
168175
<PackageReference Include="Microsoft.VisualStudio.Composition.Analyzers">
169176
<Version>16.9.20</Version>
170177
</PackageReference>
@@ -179,6 +186,9 @@
179186
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
180187
<PrivateAssets>all</PrivateAssets>
181188
</PackageReference>
189+
<PackageReference Include="Microsoft.VisualStudio.Utilities">
190+
<Version>16.10.31321.278</Version>
191+
</PackageReference>
182192
<PackageReference Include="Microsoft.VisualStudio.VCProjectEngine">
183193
<Version>16.10.31320.204</Version>
184194
</PackageReference>
@@ -189,6 +199,12 @@
189199
<PackageReference Include="Newtonsoft.Json">
190200
<Version>13.0.3</Version>
191201
</PackageReference>
202+
<PackageReference Include="NuGet.VisualStudio">
203+
<Version>5.11.6</Version>
204+
</PackageReference>
205+
<PackageReference Include="NuGet.VisualStudio.Contracts">
206+
<Version>5.11.6</Version>
207+
</PackageReference>
192208
<PackageReference Include="NUnit">
193209
<Version>3.13.1</Version>
194210
</PackageReference>
@@ -201,6 +217,9 @@
201217
<PackageReference Include="Svg">
202218
<Version>3.3.0</Version>
203219
</PackageReference>
220+
<PackageReference Include="System.CommandLine">
221+
<Version>2.0.0-beta4.22272.1</Version>
222+
</PackageReference>
204223
<PackageReference Include="System.Composition">
205224
<Version>7.0.0</Version>
206225
</PackageReference>

FineCodeCoverage2022/FineCodeCoverage2022.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
<Link>ZippedTools\coverlet.console.6.0.4.zip</Link>
110110
<IncludeInVSIX>true</IncludeInVSIX>
111111
</Content>
112+
<Content Include="..\Shared Files\ZippedTools\dotnet-coverage.17.14.2.zip">
113+
<Link>ZippedTools\dotnet-coverage.17.14.2.zip</Link>
114+
<IncludeInVSIX>true</IncludeInVSIX>
115+
</Content>
112116
<None Include="source.extension.vsixmanifest">
113117
<SubType>Designer</SubType>
114118
<Generator>VsixManifestGenerator</Generator>
@@ -188,6 +192,12 @@
188192
<PackageReference Include="Newtonsoft.Json">
189193
<Version>13.0.3</Version>
190194
</PackageReference>
195+
<PackageReference Include="NuGet.VisualStudio">
196+
<Version>17.13.2</Version>
197+
</PackageReference>
198+
<PackageReference Include="NuGet.VisualStudio.Contracts">
199+
<Version>17.13.2</Version>
200+
</PackageReference>
191201
<PackageReference Include="ReflectObject">
192202
<Version>1.0.0</Version>
193203
</PackageReference>
@@ -200,6 +210,9 @@
200210
<PackageReference Include="Svg">
201211
<Version>3.3.0</Version>
202212
</PackageReference>
213+
<PackageReference Include="System.CommandLine">
214+
<Version>2.0.0-beta4.22272.1</Version>
215+
</PackageReference>
203216
<PackageReference Include="System.Composition">
204217
<Version>8.0.0</Version>
205218
</PackageReference>

FineCodeCoverageTests/TestContainerDiscovery_Tests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using FineCodeCoverage.Engine.Model;
1010
using FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage;
1111
using FineCodeCoverage.Impl;
12+
using FineCodeCoverage.Impl.TestContainerDiscovery;
1213
using FineCodeCoverage.Options;
1314
using Microsoft.VisualStudio.TestWindow.Extensibility;
1415
using Moq;
@@ -120,6 +121,8 @@ private void SetUpOptions(Action<Mock<IAppOptions>> setupAppOptions)
120121
public void SetUp()
121122
{
122123
mocker = new AutoMoqer();
124+
var mockCoverageCollectableFromTestExplorer = mocker.GetMock<ICoverageCollectableFromTestExplorer>();
125+
mockCoverageCollectableFromTestExplorer.Setup(coverageCollectableFromTestExplorer => coverageCollectableFromTestExplorer.IsCollectableAsync()).ReturnsAsync(true);
123126
testContainerDiscoverer = mocker.Create<TestContainerDiscoverer>();
124127
testContainerDiscoverer.RunAsync = (taskProvider) =>
125128
{

README.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ or download from [releases](https://github.com/FortuneN/FineCodeCoverage/release
1414
For .Net
1515

1616
FCC supports the new [Microsoft.Testing.Platform](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-platform-intro) for MsTest, NUnit and xUnit.
17-
Support for TUnit will be available shortly but will require running tests differently.
17+
18+
Unfortunately the workaround FCC uses for MSTest, NUnit and xUnit does not apply to TUnit.
19+
TUnit has its own dedicated button on the FCC tool window toolbar and cannot be driven from the test explorer window.
20+
As the test explorer window is not used FCC cannot intercept your runsettings ( see later).
21+
Microsoft.Testing.Platform has the [Microsoft code coverage extension](https://learn.microsoft.com/en-us/dotnet/core/testing/microsoft-testing-platform-extensions-code-coverage#microsoft-code-coverage). If you add the package it will be used, otherwise FCC will run dotnet-coverage.
22+
The Microsoft code coverage extension accepts runsettings or [configuration](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-coverage#settings) and dotnet-coverage only accepts configuration.
23+
FCC will supply the necessary settings using FCC's settings system ( below ) but if you want to supply your own, FCC will read the test project file.
24+
If either the FCCTestingPlatformCommandLineArguments or TestingPlatformCommandLineArguments property is present FCC will use these [arguments](https://learn.microsoft.com/en-us/dotnet/core/testing/microsoft-testing-platform-intro?tabs=dotnetcli#options) except ones pertaining to coverage other than --coverage-settings ( or --settings) as long as the
25+
path specified exists.
26+
27+
Note that TUnit blocks coverage of your tests in the GlobalSetup.cs file if using the project template.
1828

1929
When not using Microsoft.Testing.Platform you have added test adapters through nuget packages. For instance, the NUnit Test Adapter extension is not sufficient.
2030

@@ -23,16 +33,15 @@ When not using Microsoft.Testing.Platform you have added test adapters through n
2333
## Introduction
2434

2535
Fine Code Coverage provides code coverage using one of 3 different coverage tools. In previous releases there were two coverage tools being utilised, OpenCover and Coverlet that will be referred to as 'old coverage'.
26-
Microsoft now provides a free coverage solution that you can choose to use by setting the Visual Studio Fine Code Coverage enumeration option RunMsCodeCoverage. This will probably be the preferred coverage
27-
tool for most developers.
36+
Microsoft now provides a free coverage solution that you can choose to use by setting the Visual Studio Fine Code Coverage enumeration option RunMsCodeCoverage. This will probably be the preferred coverage tool for most developers. This is not necessary for TUnit.
2837

2938
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.
3039
Thus you will find that there are separate configuration options for Ms coverage vs old coverage and options that are common to the two.
3140
Assembly level exclusions and inclusions can be achieved - see ExcludeAssemblies and IncludeAssemblies.
3241
Configuration is ( mostly ) determined from Visual Studio options, finecodecoverage-settings.xml files and project msbuild properties. All of these settings are optional.
3342
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.
3443

35-
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 and the results can be opened from buttons on the Fine Code Coverage Tool Window.
44+
Aside from TUnit projects, the process begins with FCC reacting to the test explorer in visual studio. One of the 3 coverage tools provides the coverage results and the results can be opened from buttons on the Fine Code Coverage Tool Window.
3645
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.
3746

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

Shared Files/OutputToolWindowPackage.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// ------------------------------------------------------------------------------
22
// <auto-generated>
3-
// This file was generated by VSIX Synchronizer
3+
// This file was generated by VSIX Synchronizer 1.0.44
4+
// Available from https://marketplace.visualstudio.com/items?itemName=MadsKristensen.VsixSynchronizer64
45
// </auto-generated>
56
// ------------------------------------------------------------------------------
67
namespace FineCodeCoverage
78
{
89
using System;
9-
10+
1011
/// <summary>
1112
/// Helper class that exposes all GUIDs used across VS Package.
1213
/// </summary>
@@ -24,6 +25,7 @@ internal sealed partial class PackageGuids
2425
public const string guidClearUICommandImageString = "8252a6d7-bcf3-4518-ae22-ad20ef8d4b63";
2526
public static Guid guidClearUICommandImage = new Guid(guidClearUICommandImageString);
2627
}
28+
2729
/// <summary>
2830
/// Helper class that encapsulates all CommandIDs uses across VS Package.
2931
/// </summary>
@@ -37,7 +39,9 @@ internal sealed partial class PackageIds
3739
public const int cmdidOpenCoberturaCommand = 0x0101;
3840
public const int cmdidOpenHotspotsCommand = 0x0102;
3941
public const int cmdidToggleCoverageIndicatorsCommand = 0x0103;
42+
public const int cmdidCollectTUnitCommand = 0x010C;
43+
public const int cmdidCancelCollectTUnitCommand = 0x010D;
4044
public const int outputToolWindowCommandImageIndex = 0x0001;
4145
public const int clearUICommandImageIndex = 0x0001;
4246
}
43-
}
47+
}

Shared Files/OutputToolWindowPackage.vsct

+26
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@
9191
<LocCanonicalName>FCC.OpenHotspots</LocCanonicalName>
9292
</Strings>
9393
</Button>
94+
<Button guid="guidOutputToolWindowPackageCmdSet" id="cmdidCollectTUnitCommand" priority="0x0100" type="Button">
95+
<Parent guid="guidOutputToolWindowPackageCmdSet" id="ToolWindowToolbarGroup" />
96+
<Icon guid="ImageCatalogGuid" id="RunTest" />
97+
<CommandFlag>IconIsMoniker</CommandFlag>
98+
<CommandFlag>DynamicVisibility</CommandFlag>
99+
<Strings>
100+
<ButtonText>Collect TUnit</ButtonText>
101+
<CommandName>Collect TUnit</CommandName>
102+
<CanonicalName>FCC.CollectTUnit</CanonicalName>
103+
<LocCanonicalName>FCC.CollectTUnit</LocCanonicalName>
104+
</Strings>
105+
</Button>
106+
<Button guid="guidOutputToolWindowPackageCmdSet" id="cmdidCancelCollectTUnitCommand" priority="0x0100" type="Button">
107+
<Parent guid="guidOutputToolWindowPackageCmdSet" id="ToolWindowToolbarGroup" />
108+
<Icon guid="ImageCatalogGuid" id="CancelTest" />
109+
<CommandFlag>IconIsMoniker</CommandFlag>
110+
<CommandFlag>DynamicVisibility</CommandFlag>
111+
<Strings>
112+
<ButtonText>Cancel Collect TUnit</ButtonText>
113+
<CommandName>Cancel Collect TUnit</CommandName>
114+
<CanonicalName>FCC.CancelCollectTUnit</CanonicalName>
115+
<LocCanonicalName>FCC.CancelCollectTUnit</LocCanonicalName>
116+
</Strings>
117+
</Button>
94118
</Buttons>
95119

96120
<Menus>
@@ -134,6 +158,8 @@
134158
<IDSymbol value="257" name="cmdidOpenCoberturaCommand" />
135159
<IDSymbol value="258" name="cmdidOpenHotspotsCommand" />
136160
<IDSymbol value="259" name="cmdidToggleCoverageIndicatorsCommand" />
161+
<IDSymbol value="268" name="cmdidCollectTUnitCommand" />
162+
<IDSymbol value="269" name="cmdidCancelCollectTUnitCommand" />
137163
</GuidSymbol>
138164

139165
<!-- images -->
Binary file not shown.

SharedProject/Core/FCCEngine.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.ComponentModel.Composition;
44
using System.Linq;
55
using System.Threading;
6+
using FineCodeCoverage.Core.MsTestPlatform.TestingPlatform;
67
using FineCodeCoverage.Core.Utilities;
78
using FineCodeCoverage.Engine.Cobertura;
89
using FineCodeCoverage.Engine.Model;
@@ -67,6 +68,7 @@ internal class FCCEngine : IFCCEngine,IDisposable
6768
#pragma warning restore IDE0052 // Remove unread private members
6869
private readonly IEventAggregator eventAggregator;
6970
private readonly IDisposeAwareTaskRunner disposeAwareTaskRunner;
71+
private readonly ITUnitCoverageRunner tUnitCoverageRunner;
7072
private bool disposed = false;
7173

7274
[ImportingConstructor]
@@ -82,12 +84,14 @@ public FCCEngine(
8284
ISolutionEvents solutionEvents,
8385
IAppOptionsProvider appOptionsProvider,
8486
IEventAggregator eventAggregator,
85-
IDisposeAwareTaskRunner disposeAwareTaskRunner
87+
IDisposeAwareTaskRunner disposeAwareTaskRunner,
88+
ITUnitCoverageRunner tUnitCoverageRunner
8689
)
8790
{
8891
this.solutionEvents = solutionEvents;
8992
this.eventAggregator = eventAggregator;
9093
this.disposeAwareTaskRunner = disposeAwareTaskRunner;
94+
this.tUnitCoverageRunner = tUnitCoverageRunner;
9195
solutionEvents.AfterClosing += (s,args) => ClearUI(false);
9296
appOptionsProvider.OptionsChanged += (appOptions) =>
9397
{
@@ -121,6 +125,7 @@ public void Initialize(CancellationToken cancellationToken)
121125
msTestPlatformUtil.Initialize(AppDataFolderPath, cancellationToken);
122126
coverageUtilManager.Initialize(AppDataFolderPath, cancellationToken);
123127
msCodeCoverageRunSettingsService.Initialize(AppDataFolderPath, this,cancellationToken);
128+
tUnitCoverageRunner.Initialize(AppDataFolderPath, cancellationToken);
124129
}
125130

126131
public void ClearUI(bool clearOutputWindowHistory = true)

SharedProject/Core/MsTestPlatform/CodeCoverage/ITemplatedRunSettingsService.cs

+14
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ internal interface IProjectRunSettingsFromTemplateResult
1717
List<ICoverageProject> CoverageProjectsWithFCCMsTestAdapter { get; }
1818
}
1919

20+
internal class TemplatedCoverageProjectRunSettingsResult : ICoverageProjectRunSettings
21+
{
22+
public ICoverageProject CoverageProject { get; set; }
23+
public string RunSettings { get; set; }
24+
public string CustomTemplatePath { get; internal set; }
25+
public bool ReplacedTestAdapter { get; internal set; }
26+
}
27+
2028
internal interface ITemplatedRunSettingsService
2129
{
2230
Task<IProjectRunSettingsFromTemplateResult> GenerateAsync(IEnumerable<ICoverageProject> coverageProjectsWithoutRunSettings, string solutionDirectory, string fccMsTestAdapterPath);
2331
Task CleanUpAsync(List<ICoverageProject> coverageProjects);
32+
List<TemplatedCoverageProjectRunSettingsResult> CreateProjectsRunSettings(
33+
IEnumerable<ICoverageProject> coverageProjects,
34+
string solutionDirectory,
35+
string fccMsTestAdapterPath
36+
);
37+
2438
}
2539
}

SharedProject/Core/MsTestPlatform/CodeCoverage/TemplatedRunSettingsService.cs

+1-9
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ internal class TemplatedRunSettingsService : ITemplatedRunSettingsService
1717
private readonly IRunSettingsTemplateReplacementsFactory runSettingsTemplateReplacementsFactory;
1818
private readonly IProjectRunSettingsGenerator projectRunSettingsGenerator;
1919

20-
private class TemplatedCoverageProjectRunSettingsResult : ICoverageProjectRunSettings
21-
{
22-
public ICoverageProject CoverageProject { get; set; }
23-
public string RunSettings { get; set; }
24-
public string CustomTemplatePath { get; internal set; }
25-
public bool ReplacedTestAdapter { get; internal set; }
26-
}
27-
2820
private class ProjectRunSettingsFromTemplateResult : IProjectRunSettingsFromTemplateResult
2921
{
3022
private class ExceptionReasonImpl : IExceptionReason
@@ -120,7 +112,7 @@ private IProjectRunSettingsFromTemplateResult CreateSuccessResult(IEnumerable<Te
120112
};
121113
}
122114

123-
private List<TemplatedCoverageProjectRunSettingsResult> CreateProjectsRunSettings(
115+
public List<TemplatedCoverageProjectRunSettingsResult> CreateProjectsRunSettings(
124116
IEnumerable<ICoverageProject> coverageProjects,
125117
string solutionDirectory,
126118
string fccMsTestAdapterPath

SharedProject/Core/MsTestPlatform/TestingPlatform/DisableTestingPlatformServerCapabilityGlobalPropertiesProvider.cs

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FineCodeCoverage.Engine.Model;
22
using FineCodeCoverage.Options;
3+
using Microsoft.CodeAnalysis;
34
using Microsoft.VisualStudio;
45
using Microsoft.VisualStudio.ProjectSystem;
56
using Microsoft.VisualStudio.ProjectSystem.Build;
@@ -61,18 +62,12 @@ private async Task<bool> IsTUnitAsync()
6162

6263
private async Task<bool> ProjectEnabledAsync()
6364
{
64-
var coverageProject = await GetCoverageProjectAsync();
65-
if (coverageProject != null)
66-
{
67-
var isTUnit = await IsTUnitAsync();
68-
if (isTUnit)
69-
{
70-
return false;
71-
}
72-
var projectSettings = await coverageProjectSettingsManager.GetSettingsAsync(coverageProject);
73-
return projectSettings.Enabled;
74-
}
75-
return true;
65+
var projectGuid = await GetProjectGuidAsync();
66+
if (!projectGuid.HasValue) return false;
67+
68+
var coverageProject = GetCoverageProject(projectGuid.Value);
69+
var projectSettings = await coverageProjectSettingsManager.GetSettingsAsync(coverageProject);
70+
return projectSettings.Enabled;
7671
}
7772

7873
private async Task<Guid?> GetProjectGuidAsync()
@@ -93,23 +88,18 @@ private async Task<bool> ProjectEnabledAsync()
9388
return null;
9489
}
9590

96-
private async Task<CoverageProject> GetCoverageProjectAsync()
91+
private CoverageProject GetCoverageProject(Guid projectGuid)
9792
{
98-
var projectGuid = await GetProjectGuidAsync();
99-
if (projectGuid.HasValue)
93+
return new CoverageProject(appOptionsProvider, null, coverageProjectSettingsManager, null)
10094
{
101-
return new CoverageProject(appOptionsProvider, null, coverageProjectSettingsManager, null)
102-
{
103-
Id = projectGuid.Value,
104-
ProjectFile = unconfiguredProject.FullPath
105-
};
106-
}
107-
return null;
95+
Id = projectGuid,
96+
ProjectFile = unconfiguredProject.FullPath
97+
};
10898
}
10999

110100
public override async Task<IImmutableDictionary<string, string>> GetGlobalPropertiesAsync(CancellationToken cancellationToken)
111101
{
112-
if (!AllProjectsDisabled() && await ProjectEnabledAsync())
102+
if (!await IsTUnitAsync() && !AllProjectsDisabled() && await ProjectEnabledAsync())
113103
{
114104
return Empty.PropertiesMap.Add("DisableTestingPlatformServerCapability", "true");
115105
}

0 commit comments

Comments
 (0)