Use MSTest.Sdk and make MSTest template use MSTest.Sdk (#386)

This commit is contained in:
Amaury Levé 2024-04-18 16:53:28 +02:00 коммит произвёл GitHub
Родитель b471a5d85c
Коммит 0a1074fa12
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
10 изменённых файлов: 60 добавлений и 69 удалений

Просмотреть файл

@ -20,6 +20,6 @@
<PropertyGroup Label="Testing settings">
<MicrosoftNetTestSdkVersion>17.8.0</MicrosoftNetTestSdkVersion>
<MicrosoftTestPlatformVersion>$(MicrosoftNetTestSdkVersion)</MicrosoftTestPlatformVersion>
<MSTestVersion>3.2.0</MSTestVersion>
<MSTestVersion>3.3.1</MSTestVersion>
</PropertyGroup>
</Project>

Просмотреть файл

@ -16,6 +16,7 @@
}
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24212.4"
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.24212.4",
"MSTest.Sdk": "3.3.1"
}
}

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk/3.3.1">
<PropertyGroup>
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">net9.0</TargetFramework>
@ -8,18 +8,8 @@
<Nullable>enable</Nullable>
<IsPackable Condition="'$(EnablePack)' == 'true'">true</IsPackable>
<IsPackable Condition="'$(EnablePack)' != 'true'">false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnableMSTestRunner Condition="'$(DisableRunner)' != 'true'">true</EnableMSTestRunner>
<OutputType Condition="'$(DisableRunner)' != 'true'">Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" Version="3.2.0" />
<PackageReference Condition="'$(DisableRunner)' == 'true'" Include="coverlet.collector" Version="6.0.0" />
<PackageReference Condition="'$(DisableRunner)' != 'true'" Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.1" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk/3.3.1">
<PropertyGroup>
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">net9.0</TargetFramework>
@ -6,10 +6,6 @@
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">Company.TestProject1</RootNamespace>
<IsPackable Condition="'$(EnablePack)' == 'true'">true</IsPackable>
<IsPackable Condition="'$(EnablePack)' != 'true'">false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnableMSTestRunner Condition="'$(DisableRunner)' != 'true'">true</EnableMSTestRunner>
<OutputType Condition="'$(DisableRunner)' != 'true'">Exe</OutputType>
</PropertyGroup>
<ItemGroup>
@ -17,10 +13,4 @@
<Compile Include="Tests.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MSTest" Version="3.2.0" />
<PackageReference Condition="'$(DisableRunner)' == 'true'" Include="coverlet.collector" Version="6.0.0" />
<PackageReference Condition="'$(DisableRunner)' != 'true'" Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.1" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk/3.3.1">
<PropertyGroup>
<RootNamespace>Company.TestProject1</RootNamespace>
@ -6,16 +6,6 @@
<TargetFramework Condition="'$(TargetFrameworkOverride)' != ''">TargetFrameworkOverride</TargetFramework>
<IsPackable Condition="'$(EnablePack)' == 'true'">true</IsPackable>
<IsPackable Condition="'$(EnablePack)' != 'true'">false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnableMSTestRunner Condition="'$(DisableRunner)' != 'true'">true</EnableMSTestRunner>
<OutputType Condition="'$(DisableRunner)' != 'true'">Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" Version="3.2.0" />
<PackageReference Condition="'$(DisableRunner)' == 'true'" Include="coverlet.collector" Version="6.0.0" />
<PackageReference Condition="'$(DisableRunner)' != 'true'" Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.1" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk/3.3.1">
<PropertyGroup>
<TargetFramework Condition="'$(TargetFrameworkOverride)' == ''">net9.0</TargetFramework>
@ -8,16 +8,9 @@
<Nullable>enable</Nullable>
<IsPackable Condition="'$(EnablePack)' == 'true'">true</IsPackable>
<IsPackable Condition="'$(EnablePack)' != 'true'">false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnablePlaywright>true</EnablePlaywright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="MSTest" Version="3.2.0" />
<PackageReference Include="Microsoft.Playwright.MSTest" Version="1.41.0" />
</ItemGroup>
<ItemGroup>
<Using Include="System.Text.RegularExpressions" />
<Using Include="System.Threading.Tasks" />

Просмотреть файл

@ -12,19 +12,20 @@ public sealed partial class AcceptanceTests
[
"net9.0",
];
private static readonly (string ProjectTemplateName, string ItemTemplateName, string[] Languages)[] AvailableItemTemplates =
private static readonly (string ProjectTemplateName, string ItemTemplateName, string[] Languages, bool SupportsTestingPlatform)[] AvailableItemTemplates =
[
("nunit", "nunit-test", Languages.All),
("mstest", "mstest-class", Languages.All),
("nunit", "nunit-test", Languages.All, false),
("mstest", "mstest-class", Languages.All, true),
];
private static readonly (string ProjectTemplateName, string[] Languages, bool RunDotnetTest)[] AvailableProjectTemplates =
private static readonly (string ProjectTemplateName, string[] Languages, bool RunDotnetTest, bool SupportsTestingPlatform)[] AvailableProjectTemplates =
[
("mstest", Languages.All, true),
("nunit", Languages.All, true),
("xunit", Languages.All, true),
("mstest-playwright", [Languages.CSharp], false),
("nunit-playwright", [Languages.CSharp], false),
("mstest", Languages.All, true, true),
("nunit", Languages.All, true, false),
("xunit", Languages.All, true, false),
("mstest-playwright", [Languages.CSharp], false, false),
("nunit-playwright", [Languages.CSharp], false, false),
];
[AssemblyInitialize]
@ -32,6 +33,7 @@ public sealed partial class AcceptanceTests
{
foreach (var targetFramework in SupportedTargetFrameworks)
{
DotnetUtils.InvokeDotnetNewUninstall(GetTestTemplatePath(targetFramework), false);
DotnetUtils.InvokeDotnetNewInstall(GetTestTemplatePath(targetFramework));
}
}
@ -47,7 +49,8 @@ public sealed partial class AcceptanceTests
[DataTestMethod]
[DynamicData(nameof(GetTemplateItemsToTest), DynamicDataSourceType.Method)]
public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, string projectTemplate, string itemTemplate, string language)
public void ItemTemplate_CanBeInstalledAndTestArePassing(string targetFramework, string projectTemplate, string itemTemplate,
string language, bool isTestingPlatform)
{
string testProjectName = GenerateTestProjectName();
string outputDirectory = Path.Combine(Constants.ArtifactsTempDirectory, testProjectName);
@ -72,14 +75,15 @@ public sealed partial class AcceptanceTests
var result = DotnetUtils.InvokeDotnetTest(outputDirectory);
// Verify the tests run as expected.
result.ValidateSummaryStatus(2, 0, 0);
result.ValidateSummaryStatus(isTestingPlatform, 2, 0, 0);
Directory.Delete(outputDirectory, true);
}
[DataTestMethod]
[DynamicData(nameof(GetTemplateProjectsToTest), DynamicDataSourceType.Method)]
public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramework, string projectTemplate, string language, bool runDotnetTest)
public void ProjectTemplate_CanBeInstalledAndTestsArePassing(string targetFramework, string projectTemplate, string language,
bool runDotnetTest, bool isTestingPlatform)
{
var testProjectName = GenerateTestProjectName();
string outputDirectory = Path.Combine(Constants.ArtifactsTempDirectory, testProjectName);
@ -93,7 +97,7 @@ public sealed partial class AcceptanceTests
var result = DotnetUtils.InvokeDotnetTest(outputDirectory);
// Verify the tests run as expected.
result.ValidateSummaryStatus(1, 0, 0);
result.ValidateSummaryStatus(isTestingPlatform, 1, 0, 0);
}
Directory.Delete(outputDirectory, true);
@ -103,11 +107,11 @@ public sealed partial class AcceptanceTests
{
foreach (var targetFramework in SupportedTargetFrameworks)
{
foreach (var (projectTemplate, itemTemplate, languages) in AvailableItemTemplates)
foreach (var (projectTemplate, itemTemplate, languages, supportsTestingPlatform) in AvailableItemTemplates)
{
foreach (var language in languages)
{
yield return new string[] { targetFramework, projectTemplate, itemTemplate, language };
yield return new object[] { targetFramework, projectTemplate, itemTemplate, language, supportsTestingPlatform };
}
}
}
@ -117,11 +121,11 @@ public sealed partial class AcceptanceTests
{
foreach (var targetFramework in SupportedTargetFrameworks)
{
foreach (var (projectTemplate, languages, runDotnetTest) in AvailableProjectTemplates)
foreach (var (projectTemplate, languages, runDotnetTest, supportsTestingPlatform) in AvailableProjectTemplates)
{
foreach (var language in languages)
{
yield return new object[] { targetFramework, projectTemplate, language, runDotnetTest };
yield return new object[] { targetFramework, projectTemplate, language, runDotnetTest, supportsTestingPlatform };
}
}
}

Просмотреть файл

@ -27,8 +27,8 @@ public static partial class DotnetUtils
/// Invokes <c>dotnet new uninstall</c> with specified arguments.
/// </summary>
/// <param name="arguments"></param>
public static ExecutionResult InvokeDotnetNewUninstall(string arguments)
=> InvokeDotnet("new uninstall " + arguments);
public static ExecutionResult InvokeDotnetNewUninstall(string arguments, bool assertExecution = true)
=> InvokeDotnet("new uninstall " + arguments, assertExecution);
/// <summary>
/// Invokes <c>dotnet new</c> with specified arguments.
@ -39,12 +39,12 @@ public static partial class DotnetUtils
/// <param name="language">Filters templates based on language and specifies the language of the template to create.</param>
/// <param name="outputDirectory">Location to place the generated output.</param>
public static ExecutionResult InvokeDotnetNew(string templateName, string nameAs, string? targetFramework = null, string? language = null,
string? outputDirectory = null)
string? outputDirectory = null, bool assertExecution = true)
{
var targetArgs = string.IsNullOrEmpty(targetFramework) ? "" : $" -f {targetFramework}";
var languageArgs = string.IsNullOrEmpty(language) ? "" : $" -lang {language}";
var outputArgs = string.IsNullOrEmpty(outputDirectory) ? "" : $" -o {outputDirectory}";
return InvokeDotnet($"new {templateName} -n {nameAs}{targetArgs}{languageArgs}{outputArgs}");
return InvokeDotnet($"new {templateName} -n {nameAs}{targetArgs}{languageArgs}{outputArgs}", assertExecution);
}
/// <summary>

Просмотреть файл

@ -19,7 +19,20 @@ public static class ExecutionResultExtensions
/// <param name="passedTestsCount">Passed test count</param>
/// <param name="failedTestsCount">Failed test count</param>
/// <param name="skippedTestsCount">Skipped test count</param>
public static void ValidateSummaryStatus(this ExecutionResult executionResult, int passedTestsCount, int failedTestsCount, int skippedTestsCount)
public static void ValidateSummaryStatus(this ExecutionResult executionResult, bool isTestingPlatform, int passedTestsCount, int failedTestsCount, int skippedTestsCount)
{
if (isTestingPlatform)
{
ValidateTestingPlatformSummaryStatus(executionResult, failedTestsCount == 0);
}
else
{
ValidateVSTestSummaryStatus(executionResult, passedTestsCount, failedTestsCount, skippedTestsCount);
}
}
private static void ValidateVSTestSummaryStatus(this ExecutionResult executionResult, int passedTestsCount, int failedTestsCount, int skippedTestsCount)
{
var totalTestCount = passedTestsCount + failedTestsCount + skippedTestsCount;
if (totalTestCount == 0)
@ -49,4 +62,16 @@ public static class ExecutionResultExtensions
executionResult.Arguments);
}
}
private static void ValidateTestingPlatformSummaryStatus(this ExecutionResult executionResult, bool isSuccess)
{
StringAssert.Contains(
executionResult.StandardOutput,
isSuccess ? "Tests succeeded" : "Tests failed",
"The Test summary does not match.{2}Test Output: {0}{2}Standard Error: {1}{2}Arguments: {3}{2}",
executionResult.StandardOutput,
executionResult.StandardError,
Environment.NewLine,
executionResult.Arguments);
}
}

Просмотреть файл

@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSTest.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCurrent)</TargetFramework>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
<LangVersion>preview</LangVersion>
<NoWarn>$(NoWarn);CS0105</NoWarn>
<ImplicitUsings>enable</ImplicitUsings>