Skip to content

Commit a0a6555

Browse files
committed
Use MSTest.Sdk with VSTest + parallelize
1 parent 060d805 commit a0a6555

11 files changed

+29
-25
lines changed

CommunityToolkit.Tooling.SampleGen.Tests/CommunityToolkit.Tooling.SampleGen.Tests.csproj

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="MSTest.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
6-
7-
<IsPackable>false</IsPackable>
86
<LangVersion>preview</LangVersion>
7+
<UseVSTest>true</UseVSTest>
98
</PropertyGroup>
109

1110
<ItemGroup>
1211
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
14-
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
15-
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
1612
</ItemGroup>
1713

1814
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]
8+
[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)]

CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleGeneratedPaneTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
using CommunityToolkit.Tooling.SampleGen.Diagnostics;
66
using CommunityToolkit.Tooling.SampleGen.Tests.Helpers;
7-
using Microsoft.CodeAnalysis;
87
using Microsoft.VisualStudio.TestTools.UnitTesting;
9-
using System.Linq;
108

119
namespace CommunityToolkit.Tooling.SampleGen.Tests;
1210

CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.Documentation.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Which is valid.
300300

301301
result.AssertNoCompilationErrors();
302302

303-
Assert.AreEqual(result.Compilation.GetFileContentsByName("ToolkitDocumentRegistry.g.cs"), """
303+
Assert.AreEqual("""
304304
#nullable enable
305305
namespace CommunityToolkit.Tooling.SampleGen;
306306
@@ -311,6 +311,6 @@ public static class ToolkitDocumentRegistry
311311
yield return new CommunityToolkit.Tooling.SampleGen.Metadata.ToolkitFrontMatter() { ComponentName = "Primitives", Title = "Canvas Layout", Author = "mhawker", Description = "A canvas-like VirtualizingLayout for use in an ItemsRepeater", Keywords = "CanvasLayout, ItemsRepeater, VirtualizingLayout, Canvas, Layout, Panel, Arrange", Category = ToolkitSampleCategory.Controls, Subcategory = ToolkitSampleSubcategory.Layout, DiscussionId = 0, IssueId = 0, Icon = @"assets/icon.png", FilePath = @"experiment\samples\documentation.md", SampleIdReferences = new string[] { "Sample" }, IsExperimental = true, CsProjName = @"componentname.csproj" };
312312
}
313313
}
314-
""", "Unexpected code generated");
314+
""", result.Compilation.GetFileContentsByName("ToolkitDocumentRegistry.g.cs"), "Unexpected code generated");
315315
}
316316
}

CommunityToolkit.Tooling.SampleGen.Tests/ToolkitSampleMetadataTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using CommunityToolkit.Tooling.SampleGen.Diagnostics;
66
using CommunityToolkit.Tooling.SampleGen.Tests.Helpers;
77
using Microsoft.VisualStudio.TestTools.UnitTesting;
8-
using System.Collections.Immutable;
9-
using System.ComponentModel.DataAnnotations;
108

119
namespace CommunityToolkit.Tooling.SampleGen.Tests;
1210

CommunityToolkit.Tooling.TestGen.Tests/CommunityToolkit.Tooling.TestGen.Tests.csproj

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="MSTest.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
6-
7-
<IsPackable>false</IsPackable>
6+
<UseVSTest>true</UseVSTest>
87
</PropertyGroup>
98

109
<ItemGroup>
1110
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
13-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
14-
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
1511
</ItemGroup>
1612

1713
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]
8+
[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)]

CommunityToolkit.Tooling.TestGen.Tests/UIThreadTestMethodTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,10 @@ from assembly in AppDomain.CurrentDomain.GetAssemblies()
340340
driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out Compilation outputCompilation, out ImmutableArray<Diagnostic> diagnostics);
341341

342342
HashSet<string> resultingIds = diagnostics.Select(diagnostic => diagnostic.Id).ToHashSet();
343-
var generatedCompilationDiaghostics = outputCompilation.GetDiagnostics();
343+
var generatedCompilationDiagnostics = outputCompilation.GetDiagnostics();
344344

345345
Assert.IsTrue(resultingIds.SetEquals(diagnosticsIds), $"Expected one of [{string.Join(", ", diagnosticsIds)}] diagnostic Ids. Got [{string.Join(", ", resultingIds)}]");
346-
Assert.IsTrue(generatedCompilationDiaghostics.All(x => x.Severity != DiagnosticSeverity.Error), $"Expected no generated compilation errors. Got: \n{string.Join("\n", generatedCompilationDiaghostics.Where(x => x.Severity == DiagnosticSeverity.Error).Select(x => $"[{x.Id}: {x.GetMessage()}]"))}");
346+
Assert.IsTrue(generatedCompilationDiagnostics.All(x => x.Severity != DiagnosticSeverity.Error), $"Expected no generated compilation errors. Got: \n{string.Join("\n", generatedCompilationDiagnostics.Where(x => x.Severity == DiagnosticSeverity.Error).Select(x => $"[{x.Id}: {x.GetMessage()}]"))}");
347347

348348
GC.KeepAlive(attributeType);
349349

ProjectHeads/Tests.Head.WinAppSdk.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Import Project="$(MSBuildThisFileDirectory)\Head.WinAppSdk.props"/>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.11.1">
9+
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.13.0">
1010
<ExcludeAssets>build</ExcludeAssets>
1111
</PackageReference>
1212
</ItemGroup>

ProjectHeads/Tests.Head.props

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
<!-- Test Dependencies -->
1212
<ItemGroup>
13-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10"/>
14-
<PackageReference Include="MSTest.TestFramework" Version="2.2.10"/>
13+
<PackageReference Include="MSTest" Version="3.7.3"/>
1514

1615
<ProjectReference Include="$(ToolingDirectory)\CommunityToolkit.Tooling.TestGen\CommunityToolkit.Tooling.TestGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="True" />
1716
</ItemGroup>

global.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "9.0.101",
44
"rollForward": "latestFeature"
55
},
6-
"msbuild-sdks":
6+
"msbuild-sdks":
77
{
8-
"MSBuild.Sdk.Extras":"3.0.23"
8+
"MSBuild.Sdk.Extras":"3.0.23",
9+
"MSTest.Sdk": "3.7.3"
910
}
1011
}

0 commit comments

Comments
 (0)