Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,22 @@
<Compile Include="$(IntermediateOutputPath)BuildInfo.cs" />
</ItemGroup>
</Target>

<!-- Validates that the literal versions declared on the MSTest.Sdk-bundled feature PackageVersion items
in Directory.Packages.props stay in sync with the matching scalar *Version properties consumed by the
build. Authored here (rather than in Directory.Packages.props) because targets belong in .targets
files; the PackageVersion items it references are populated before this target executes regardless of
which file declares it. -->
<Target Name="_ValidateBundledSdkFeatureVersions"
BeforeTargets="CollectPackageReferences;GenerateNuspec;Build;Pack"
Condition=" '$(MSBuildProjectName)' == 'MSTest.Sdk' ">
<PropertyGroup>
<_AspireHostingTestingPackageVersion>@(PackageVersion->WithMetadataValue('Identity', 'Aspire.Hosting.Testing')->'%(Version)')</_AspireHostingTestingPackageVersion>
<_MicrosoftPlaywrightPackageVersion>@(PackageVersion->WithMetadataValue('Identity', 'Microsoft.Playwright.MSTest.v4')->'%(Version)')</_MicrosoftPlaywrightPackageVersion>
</PropertyGroup>
<Error Condition=" '$(AspireHostingTestingVersion)' != '$(_AspireHostingTestingPackageVersion)' "
Text="AspireHostingTestingVersion ('$(AspireHostingTestingVersion)') is out of sync with the 'Aspire.Hosting.Testing' PackageVersion ('$(_AspireHostingTestingPackageVersion)') in Directory.Packages.props. Update the AspireHostingTestingVersion property to match (Dependabot only updates the PackageVersion)." />
<Error Condition=" '$(MicrosoftPlaywrightVersion)' != '$(_MicrosoftPlaywrightPackageVersion)' "
Text="MicrosoftPlaywrightVersion ('$(MicrosoftPlaywrightVersion)') is out of sync with the 'Microsoft.Playwright.MSTest.v4' PackageVersion ('$(_MicrosoftPlaywrightPackageVersion)') in Directory.Packages.props. Update the MicrosoftPlaywrightVersion property to match (Dependabot only updates the PackageVersion)." />
</Target>
</Project>
18 changes: 3 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,12 @@
template (see MSTest.Sdk.csproj). The two cannot be unified because the consuming property must
be a plain scalar (an item transform such as @(PackageVersion->...) stored in a property is not
expanded and breaks string concatenation, e.g. MSB4012), while Dependabot needs the literal on
the PackageVersion. The _ValidateBundledSdkFeatureVersions target below fails the build if the
property and the PackageVersion ever drift apart (e.g. after Dependabot bumps only the
PackageVersion), so the duplication can never ship out of sync.
the PackageVersion. The _ValidateBundledSdkFeatureVersions target (in Directory.Build.targets)
fails the build if the property and the PackageVersion ever drift apart (e.g. after Dependabot
bumps only the PackageVersion), so the duplication can never ship out of sync.
-->
<ItemGroup Label="Declared by MSTest.Sdk but not used directly">
<PackageVersion Include="Aspire.Hosting.Testing" Version="13.4.6" />
<PackageVersion Include="Microsoft.Playwright.MSTest.v4" Version="1.60.0" />
</ItemGroup>
<Target Name="_ValidateBundledSdkFeatureVersions"
BeforeTargets="CollectPackageReferences;GenerateNuspec;Build;Pack"
Condition=" '$(MSBuildProjectName)' == 'MSTest.Sdk' ">
<PropertyGroup>
<_AspireHostingTestingPackageVersion>@(PackageVersion->WithMetadataValue('Identity', 'Aspire.Hosting.Testing')->'%(Version)')</_AspireHostingTestingPackageVersion>
<_MicrosoftPlaywrightPackageVersion>@(PackageVersion->WithMetadataValue('Identity', 'Microsoft.Playwright.MSTest.v4')->'%(Version)')</_MicrosoftPlaywrightPackageVersion>
</PropertyGroup>
<Error Condition=" '$(AspireHostingTestingVersion)' != '$(_AspireHostingTestingPackageVersion)' "
Text="AspireHostingTestingVersion ('$(AspireHostingTestingVersion)') is out of sync with the 'Aspire.Hosting.Testing' PackageVersion ('$(_AspireHostingTestingPackageVersion)') in Directory.Packages.props. Update the AspireHostingTestingVersion property to match (Dependabot only updates the PackageVersion)." />
<Error Condition=" '$(MicrosoftPlaywrightVersion)' != '$(_MicrosoftPlaywrightPackageVersion)' "
Text="MicrosoftPlaywrightVersion ('$(MicrosoftPlaywrightVersion)') is out of sync with the 'Microsoft.Playwright.MSTest.v4' PackageVersion ('$(_MicrosoftPlaywrightPackageVersion)') in Directory.Packages.props. Update the MicrosoftPlaywrightVersion property to match (Dependabot only updates the PackageVersion)." />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<MSTestSourceGenMode Condition=" '$(MSTestSourceGenMode)' == '' ">Rooting</MSTestSourceGenMode>
</PropertyGroup>

<Target Name="GetMSTestV2CultureHierarchy">
<Target Name="GetMSTestV2CultureHierarchy" Returns="@(MSTestV2Files)">
<!--
Only traversing 5 levels in the culture hierarchy. This is the maximum length for all cultures and should be sufficient
to get to a culture name that maps to a resource folder we package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<CompilerVisibleProperty Include="IsMSTestTestAdapterReferenced" />
</ItemGroup>

<Target Name="GetMSTestV2CultureHierarchy">
<Target Name="GetMSTestV2CultureHierarchy" Returns="@(MSTestV2Files)">
<!--
Only traversing 5 levels in the culture hierarchy. This is the maximum length for all cultures and should be sufficient
to get to a culture name that maps to a resource folder we package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class AvoidThreadSleepAndTaskWaitInTestsAnalyzer : DiagnosticAnaly
Title,
MessageFormat,
Description,
Category.Usage,
Category.Performance,
DiagnosticSeverity.Info,
isEnabledByDefault: false);

Expand Down
12 changes: 9 additions & 3 deletions src/Analyzers/MSTest.Analyzers/Helpers/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ namespace MSTest.Analyzers.Helpers;
internal enum Category
{
/// <summary>
/// Rules that support designing test suites.
/// Rules that support designing test suites — structural and organizational patterns such as how test
/// classes, fixtures, and data sources are shaped. Use this for guidance that improves the maintainability
/// or correctness of the test design rather than raw API usage or runtime cost.
/// </summary>
Design,

/// <summary>
/// Rules that support high-performance testing.
/// Rules that support high-performance testing — patterns that measurably affect test-suite execution time
/// or resource usage. Use this for blocking calls (e.g. <c>Thread.Sleep</c>/<c>Task.Wait</c>), missing
/// parallelism, or non-cooperative timeouts that keep threads busy after a test has timed out.
/// </summary>
Performance,

/// <summary>
/// Rules that support proper usage of MSTest.
/// Rules that support proper usage of MSTest — correct API usage such as valid method signatures, required
/// attributes, and avoiding misused APIs. Use this when the diagnostic is about using the framework
/// correctly rather than test design or runtime performance.
/// </summary>
Usage,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ internal static bool TryGetFixtureMethodSymbols(
return true;
}

/// <summary>
/// Registers the standard symbol analysis for an instance fixture method (e.g. <c>[TestInitialize]</c> or
/// <c>[TestCleanup]</c>): reports <paramref name="rule"/> for methods that do not have a valid instance
/// fixture signature. Callers remain responsible for <c>ConfigureGeneratedCodeAnalysis</c> /
/// <c>EnableConcurrentExecution</c> as required by the RS1025/RS1026 analyzers.
/// </summary>
internal static void RegisterInstanceFixtureAnalyzer(
AnalysisContext context,
string fixtureAttributeMetadataName,
DiagnosticDescriptor rule)
=> RegisterFixtureMethodSymbolAction(
context,
fixtureAttributeMetadataName,
(symbolContext, symbols) => AnalyzeInstanceFixtureMethod(symbolContext, symbols, rule));

internal static void RegisterFixtureMethodSymbolAction(
AnalysisContext context,
string fixtureAttributeMetadataName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
FixtureMethodAnalyzerHelper.RegisterFixtureMethodSymbolAction(
FixtureMethodAnalyzerHelper.RegisterInstanceFixtureAnalyzer(
context,
WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingTestCleanupAttribute,
static (symbolContext, symbols) => FixtureMethodAnalyzerHelper.AnalyzeInstanceFixtureMethod(symbolContext, symbols, Rule));
Rule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
FixtureMethodAnalyzerHelper.RegisterFixtureMethodSymbolAction(
FixtureMethodAnalyzerHelper.RegisterInstanceFixtureAnalyzer(
context,
WellKnownTypeNames.MicrosoftVisualStudioTestToolsUnitTestingTestInitializeAttribute,
static (symbolContext, symbols) => FixtureMethodAnalyzerHelper.AnalyzeInstanceFixtureMethod(symbolContext, symbols, Rule));
Rule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public CtrfReportEngine(
{
}

public CtrfReportEngine(ReportEngineContext context)
: base(context)
{
}

public Task<(string FileName, string? Warning)> GenerateReportAsync(CapturedTestResult[] results)
=> GenerateReportCoreAsync(results, _clock.UtcNow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ protected override string GetGenerationLogMessage(int testResultCount)
int exitCode,
CancellationToken cancellationToken)
{
var engine = new CtrfReportEngine(
FileSystem,
TestApplicationModuleInfo,
Environment,
CommandLineOptions,
Configuration,
Clock,
TestFramework,
testStartTime,
exitCode,
cancellationToken);
var engine = new CtrfReportEngine(CreateEngineContext(testStartTime, exitCode, cancellationToken));
return engine.GenerateReportAsync(tests);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ This package extends Microsoft Testing Platform to produce test reports in the C
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameHelper.cs" Link="Helpers\ReportFileNameHelper.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameSanitizer.cs" Link="Helpers\ReportFileNameSanitizer.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineBase.cs" Link="Helpers\ReportEngineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineContext.cs" Link="Helpers\ReportEngineContext.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorBase.cs" Link="Helpers\ReportGeneratorBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportProviderRegistration.cs" Link="Helpers\ReportProviderRegistration.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorCommandLineBase.cs" Link="Helpers\ReportGeneratorCommandLineBase.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public HtmlReportEngine(
{
}

public HtmlReportEngine(ReportEngineContext context)
: base(context)
{
}

public Task<(string FileName, string? Warning)> GenerateReportAsync(CapturedTestResult[] results)
=> GenerateReportCoreAsync(results, _clock.UtcNow);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ protected override string GetGenerationLogMessage(int testResultCount)
int exitCode,
CancellationToken cancellationToken)
{
var engine = new HtmlReportEngine(
FileSystem,
TestApplicationModuleInfo,
Environment,
CommandLineOptions,
Configuration,
Clock,
TestFramework,
testStartTime,
exitCode,
cancellationToken);
var engine = new HtmlReportEngine(CreateEngineContext(testStartTime, exitCode, cancellationToken));
return engine.GenerateReportAsync(tests);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This package extends Microsoft Testing Platform to produce self-contained HTML t
<Compile Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Resources\PlatformResources.cs" Link="Resources\PlatformResources.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameValidator.cs" Link="Helpers\ReportFileNameValidator.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineBase.cs" Link="Helpers\ReportEngineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineContext.cs" Link="Helpers\ReportEngineContext.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorBase.cs" Link="Helpers\ReportGeneratorBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportProviderRegistration.cs" Link="Helpers\ReportProviderRegistration.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorCommandLineBase.cs" Link="Helpers\ReportGeneratorCommandLineBase.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public JUnitReportEngine(
{
}

public JUnitReportEngine(ReportEngineContext context)
: base(context)
{
}

public Task<(string FileName, string? Warning)> GenerateReportAsync(
CapturedTestResult[] results,
IReadOnlyDictionary<string, TestResultCapture.ParentChainEntry> parentChain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,7 @@ protected override void OnTestNodeUpdate(TestNodeUpdateMessage update)
int exitCode,
CancellationToken cancellationToken)
{
var engine = new JUnitReportEngine(
FileSystem,
TestApplicationModuleInfo,
Environment,
CommandLineOptions,
Configuration,
Clock,
TestFramework,
testStartTime,
exitCode,
cancellationToken);
var engine = new JUnitReportEngine(CreateEngineContext(testStartTime, exitCode, cancellationToken));
return engine.GenerateReportAsync(tests, _parentChain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ This package extends Microsoft Testing Platform to produce JUnit XML test report
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\CapturedTestResultBase.cs" Link="Helpers\CapturedTestResultBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameValidator.cs" Link="Helpers\ReportFileNameValidator.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineBase.cs" Link="Helpers\ReportEngineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineContext.cs" Link="Helpers\ReportEngineContext.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorBase.cs" Link="Helpers\ReportGeneratorBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportProviderRegistration.cs" Link="Helpers\ReportProviderRegistration.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorCommandLineBase.cs" Link="Helpers\ReportGeneratorCommandLineBase.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameSanitizer.cs" Link="Helpers\ReportFileNameSanitizer.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportGeneratorCommandLineBase.cs" Link="Helpers\ReportGeneratorCommandLineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineBase.cs" Link="Helpers\ReportEngineBase.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportEngineContext.cs" Link="Helpers\ReportEngineContext.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileNameValidator.cs" Link="Helpers\ReportFileNameValidator.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\ReportFileWriterHelper.cs" Link="Helpers\ReportFileWriterHelper.cs" />
<Compile Include="$(RepoRoot)src\Platform\SharedExtensionHelpers\TargetFrameworkMonikerHelper.cs" Link="Helpers\TargetFrameworkMonikerHelper.cs" />
Expand Down
Loading