diff --git a/Directory.Packages.props b/Directory.Packages.props index cf6e363599..6ddbf71dfa 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -25,6 +25,7 @@ 1.1.3-beta1.24423.1 + 3.8.0-preview.24616.6 @@ -65,12 +66,13 @@ - - + + + diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs index 06ecd53fbe..da68aed004 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs @@ -9,12 +9,11 @@ using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; -using Microsoft.VisualStudio.TestTools.UnitTesting; #endif using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; +using Microsoft.VisualStudio.TestTools.UnitTesting; using ITestDataSource = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ITestDataSource; -using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; @@ -36,9 +35,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; public class TestDataSource : ITestDataSource { #if NETFRAMEWORK - public IEnumerable? GetData(UTF.ITestMethod testMethodInfo, ITestContext testContext) + public IEnumerable? GetData(ITestMethod testMethodInfo, ITestContext testContext) #else - IEnumerable? ITestDataSource.GetData(UTF.ITestMethod testMethodInfo, ITestContext testContext) + IEnumerable? ITestDataSource.GetData(ITestMethod testMethodInfo, ITestContext testContext) #endif { #if NETFRAMEWORK @@ -49,12 +48,12 @@ public class TestDataSource : ITestDataSource Path.GetDirectoryName(new Uri(testMethodInfo.MethodInfo.Module.Assembly.CodeBase).LocalPath), ]; - List dataRowResults = []; + List dataRowResults = []; // Connect to data source. TestDataConnectionFactory factory = new(); - GetConnectionProperties(testMethodInfo.GetAttributes(false)[0], out string providerNameInvariant, out string? connectionString, out string? tableName, out UTF.DataAccessMethod dataAccessMethod); + GetConnectionProperties(testMethodInfo.GetAttributes(false)[0], out string providerNameInvariant, out string? connectionString, out string? tableName, out DataAccessMethod dataAccessMethod); try { @@ -103,7 +102,7 @@ public class TestDataSource : ITestDataSource /// The data access method. /// Number of permutations. /// Permutations. - private static IEnumerable GetPermutation(UTF.DataAccessMethod dataAccessMethod, int length) + private static IEnumerable GetPermutation(DataAccessMethod dataAccessMethod, int length) { switch (dataAccessMethod) { @@ -127,8 +126,8 @@ private static IEnumerable GetPermutation(UTF.DataAccessMethod dataAccessMe /// The connection string. /// The table name. /// The data access method. - private static void GetConnectionProperties(UTF.DataSourceAttribute dataSourceAttribute, out string providerNameInvariant, - out string? connectionString, out string? tableName, out UTF.DataAccessMethod dataAccessMethod) + private static void GetConnectionProperties(DataSourceAttribute dataSourceAttribute, out string providerNameInvariant, + out string? connectionString, out string? tableName, out DataAccessMethod dataAccessMethod) { if (StringEx.IsNullOrEmpty(dataSourceAttribute.DataSourceSettingName)) { @@ -139,7 +138,7 @@ private static void GetConnectionProperties(UTF.DataSourceAttribute dataSourceAt return; } - UTF.DataSourceElement element = TestConfiguration.ConfigurationSection.DataSources[dataSourceAttribute.DataSourceSettingName] + DataSourceElement element = TestConfiguration.ConfigurationSection.DataSources[dataSourceAttribute.DataSourceSettingName] #pragma warning disable CA2201 // Do not raise reserved exception types ?? throw new Exception(string.Format(CultureInfo.CurrentCulture, Resource.UTA_DataSourceConfigurationSectionMissing, dataSourceAttribute.DataSourceSettingName)); #pragma warning restore CA2201 // Do not raise reserved exception types diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/FileUtility.cs b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/FileUtility.cs index cc5b3efeb1..708fff0ec5 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Utilities/FileUtility.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Utilities/FileUtility.cs @@ -86,7 +86,7 @@ public virtual string GetNextIterationDirectoryName(string parentDirectoryName, /// Returns empty string on error when specified to continue the run on error, /// throw on error when specified to abort the run on error. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] public virtual string CopyFileOverwrite(string source, string destination, out string? warning) { DebugEx.Assert(!StringEx.IsNullOrEmpty(source), "source should not be null."); @@ -224,7 +224,7 @@ public static string TryConvertPathToRelative(string path, string rootDir) /// them. /// /// The root directory to clear. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] public virtual void DeleteDirectories(string filePath) { Guard.NotNullOrWhiteSpace(filePath); @@ -255,7 +255,7 @@ public virtual void DeleteDirectories(string filePath) /// /// path to symbols file. /// Pdb file name or null if non-existent. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] private static string? GetSymbolsFileName(string? path) { if (StringEx.IsNullOrEmpty(path) || path.IndexOfAny(Path.GetInvalidPathChars()) != -1) diff --git a/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/WellKnownTypeProvider.cs b/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/WellKnownTypeProvider.cs index 13290e5703..f988d950c2 100644 --- a/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/WellKnownTypeProvider.cs +++ b/src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/WellKnownTypeProvider.cs @@ -171,12 +171,12 @@ private bool TryGetOrCreateTypeByMetadataNameSlow( } /// - /// Determines if is a with its type + /// Determines if is a with its type /// argument satisfying . /// - /// Type potentially representing a . + /// Type potentially representing a . /// Predicate to check the 's type argument. - /// True if is a with its + /// True if is a with its /// type argument satisfying , false otherwise. internal bool IsTaskOfType([NotNullWhen(returnValue: true)] ITypeSymbol? typeSymbol, Func typeArgumentPredicate) => typeSymbol != null diff --git a/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj b/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj index f711a190c2..6d7d59466d 100644 --- a/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj @@ -42,7 +42,6 @@ This package extends Microsoft Testing Platform to provide a crash dump function - diff --git a/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj b/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj index 336a3f8003..0cfd477f7f 100644 --- a/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj @@ -50,7 +50,6 @@ This package extends Microsoft Testing Platform to provide TRX test reports.]]> - diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj index 64a5152e66..a3d08254e9 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj @@ -5,8 +5,6 @@ - - diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FastFilter.cs b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FastFilter.cs index 6e596db037..3e0ec2232c 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FastFilter.cs +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/FastFilter.cs @@ -195,14 +195,15 @@ private void AddProperty(string name, string value) { if (!_filterDictionaryBuilder.TryGetValue(name, out ImmutableHashSet.Builder? values)) { - values = ImmutableHashSet.CreateBuilder(StringComparer.OrdinalIgnoreCase); + values = ImmutableHashSet.CreateBuilder(StringComparer.OrdinalIgnoreCase)!; _filterDictionaryBuilder.Add(name, values); } values.Add(value); } - internal FastFilter? ToFastFilter() => ContainsValidFilter + internal FastFilter? ToFastFilter() + => ContainsValidFilter ? new FastFilter( _filterDictionaryBuilder.ToImmutableDictionary(kvp => kvp.Key, kvp => (ISet)_filterDictionaryBuilder[kvp.Key].ToImmutable()), _fastFilterOperation, diff --git a/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj b/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj index 20f935bb6b..65d829e792 100644 --- a/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj +++ b/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj @@ -63,8 +63,6 @@ This package provides the core platform and the .NET implementation of the proto - - diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs index e99de710ee..f3e486205d 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs @@ -218,10 +218,10 @@ static SerializerUtilities() #if NETCOREAPP properties[namedKvpStringProperty.Name] = namedKvpStringProperty.Pairs; #else - Jsonite.JsonArray collection = []; + JsonArray collection = []; foreach (KeyValuePair item in namedKvpStringProperty.Pairs) { - Jsonite.JsonObject o = new() + JsonObject o = new() { { item.Key, item.Value }, }; @@ -419,10 +419,10 @@ static SerializerUtilities() #if NETCOREAPP values[JsonRpcStrings.EnvironmentVariables] = ev.EnvironmentVariables; #else - Jsonite.JsonArray collection = []; + JsonArray collection = []; foreach (KeyValuePair item in ev.EnvironmentVariables) { - Jsonite.JsonObject o = new() + JsonObject o = new() { { item.Key, item.Value }, }; diff --git a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs index 91fde548cd..602e795cfc 100644 --- a/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs +++ b/src/TestFramework/TestFramework.Extensions/ConfigurationSettings/TestConfigurationSection.cs @@ -24,7 +24,7 @@ public sealed class TestConfigurationSection : ConfigurationSection /// Gets the collection of properties. /// /// - /// The of properties for the element. + /// The of properties for the element. /// protected override ConfigurationPropertyCollection Properties { get; } = [DataSourcesValue]; } diff --git a/src/TestFramework/TestFramework.Extensions/PrivateObject.cs b/src/TestFramework/TestFramework.Extensions/PrivateObject.cs index 48a7b255eb..ba97ebbbdd 100644 --- a/src/TestFramework/TestFramework.Extensions/PrivateObject.cs +++ b/src/TestFramework/TestFramework.Extensions/PrivateObject.cs @@ -73,7 +73,7 @@ public PrivateObject(string assemblyName, string typeName, params object?[]? arg /// /// Name of the assembly. /// fully qualified name. - /// An array of objects representing the number, order, and type of the parameters for the constructor to get. + /// An array of objects representing the number, order, and type of the parameters for the constructor to get. /// Arguments to pass to the constructor. public PrivateObject(string assemblyName, string typeName, Type[]? parameterTypes, object?[]? args) : this(Type.GetType(string.Format(CultureInfo.InvariantCulture, "{0}, {1}", typeName, assemblyName), false), parameterTypes, args) @@ -97,7 +97,7 @@ public PrivateObject(Type type, params object?[]? args) /// specified type. /// /// type of the object to create. - /// An array of objects representing the number, order, and type of the parameters for the constructor to get. + /// An array of objects representing the number, order, and type of the parameters for the constructor to get. /// Arguments to pass to the constructor. public PrivateObject(Type type, Type[]? parameterTypes, object?[]? args) { @@ -241,7 +241,7 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// An array of objects representing the number, order, and type of the parameters for the method to get. /// Arguments to pass to the member to invoke. /// Result of method call. public object? Invoke(string name, Type[] parameterTypes, object?[]? args) => Invoke(name, parameterTypes, args, CultureInfo.InvariantCulture); @@ -250,7 +250,7 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// An array of objects representing the number, order, and type of the parameters for the method to get. /// Arguments to pass to the member to invoke. /// An array of types corresponding to the types of the generic arguments. /// Result of method call. @@ -269,7 +269,7 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// An array of objects representing the number, order, and type of the parameters for the method to get. /// Arguments to pass to the member to invoke. /// Culture info. /// Result of method call. @@ -279,7 +279,7 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// Arguments to pass to the member to invoke. /// Result of method call. public object? Invoke(string name, BindingFlags bindingFlags, params object?[]? args) => Invoke(name, bindingFlags, null, args, CultureInfo.InvariantCulture); @@ -288,8 +288,8 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// A bitmask comprised of one or more that specify how the search is conducted. - /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// A bitmask comprised of one or more that specify how the search is conducted. + /// An array of objects representing the number, order, and type of the parameters for the method to get. /// Arguments to pass to the member to invoke. /// Result of method call. public object? Invoke(string name, BindingFlags bindingFlags, Type[] parameterTypes, object?[]? args) => Invoke(name, bindingFlags, parameterTypes, args, CultureInfo.InvariantCulture); @@ -298,7 +298,7 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// Arguments to pass to the member to invoke. /// Culture info. /// Result of method call. @@ -308,8 +308,8 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// A bitmask comprised of one or more that specify how the search is conducted. - /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// A bitmask comprised of one or more that specify how the search is conducted. + /// An array of objects representing the number, order, and type of the parameters for the method to get. /// Arguments to pass to the member to invoke. /// Culture info. /// Result of method call. @@ -319,8 +319,8 @@ public override bool Equals(object? obj) /// Invokes the specified method. /// /// Name of the method. - /// A bitmask comprised of one or more that specify how the search is conducted. - /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// A bitmask comprised of one or more that specify how the search is conducted. + /// An array of objects representing the number, order, and type of the parameters for the method to get. /// Arguments to pass to the member to invoke. /// Culture info. /// An array of types corresponding to the types of the generic arguments. @@ -408,7 +408,7 @@ public void SetArrayElement(string name, object value, params int[] indices) /// Gets the array element using array of subscripts for each dimension. /// /// Name of the member. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// the indices of array. /// An array of elements. public object GetArrayElement(string name, BindingFlags bindingFlags, params int[] indices) @@ -423,7 +423,7 @@ public object GetArrayElement(string name, BindingFlags bindingFlags, params int /// Sets the array element using array of subscripts for each dimension. /// /// Name of the member. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// Value to set. /// the indices of array. public void SetArrayElement(string name, BindingFlags bindingFlags, object value, params int[] indices) @@ -460,7 +460,7 @@ public void SetField(string name, object value) /// Gets the field. /// /// Name of the field. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// The field. public object? GetField(string name, BindingFlags bindingFlags) { @@ -472,7 +472,7 @@ public void SetField(string name, object value) /// Sets the field. /// /// Name of the field. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// value to set. public void SetField(string name, BindingFlags bindingFlags, object? value) { @@ -506,7 +506,7 @@ public void SetFieldOrProperty(string name, object value) /// Gets the field or property. /// /// Name of the field or property. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// The field or property. public object? GetFieldOrProperty(string name, BindingFlags bindingFlags) { @@ -518,7 +518,7 @@ public void SetFieldOrProperty(string name, object value) /// Sets the field or property. /// /// Name of the field or property. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// value to set. public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? value) { @@ -538,7 +538,7 @@ public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? v /// Gets the property. /// /// Name of the property. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// Arguments to pass to the member to invoke. /// The property. public object? GetProperty(string name, Type[]? parameterTypes, object?[]? args) => GetProperty(name, BindToEveryThing, parameterTypes, args); @@ -555,7 +555,7 @@ public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? v /// Set the property. /// /// Name of the property. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// value to set. /// Arguments to pass to the member to invoke. public void SetProperty(string name, Type[]? parameterTypes, object? value, object?[]? args) => SetProperty(name, BindToEveryThing, value, parameterTypes, args); @@ -564,7 +564,7 @@ public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? v /// Gets the property. /// /// Name of the property. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// Arguments to pass to the member to invoke. /// The property. public object? GetProperty(string name, BindingFlags bindingFlags, params object?[]? args) => GetProperty(name, bindingFlags, null, args); @@ -573,8 +573,8 @@ public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? v /// Gets the property. /// /// Name of the property. - /// A bitmask comprised of one or more that specify how the search is conducted. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// A bitmask comprised of one or more that specify how the search is conducted. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// Arguments to pass to the member to invoke. /// The property. public object? GetProperty(string name, BindingFlags bindingFlags, Type[]? parameterTypes, object?[]? args) @@ -594,7 +594,7 @@ public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? v /// Sets the property. /// /// Name of the property. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// value to set. /// Arguments to pass to the member to invoke. public void SetProperty(string name, BindingFlags bindingFlags, object value, params object?[]? args) => SetProperty(name, bindingFlags, value, null, args); @@ -603,9 +603,9 @@ public void SetFieldOrProperty(string name, BindingFlags bindingFlags, object? v /// Sets the property. /// /// Name of the property. - /// A bitmask comprised of one or more that specify how the search is conducted. + /// A bitmask comprised of one or more that specify how the search is conducted. /// value to set. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// Arguments to pass to the member to invoke. public void SetProperty(string name, BindingFlags bindingFlags, object? value, Type[]? parameterTypes, object?[]? args) { diff --git a/src/TestFramework/TestFramework.Extensions/PrivateType.cs b/src/TestFramework/TestFramework.Extensions/PrivateType.cs index c9733d65cb..9d188e76d8 100644 --- a/src/TestFramework/TestFramework.Extensions/PrivateType.cs +++ b/src/TestFramework/TestFramework.Extensions/PrivateType.cs @@ -59,7 +59,7 @@ public PrivateType(Type type) => /// Invokes static member. /// /// Name of the member to InvokeHelper. - /// An array of objects representing the number, order, and type of the parameters for the method to invoke. + /// An array of objects representing the number, order, and type of the parameters for the method to invoke. /// Arguments to the invocation. /// Result of invocation. public object InvokeStatic(string name, Type[]? parameterTypes, object?[]? args) => InvokeStatic(name, parameterTypes, args, CultureInfo.InvariantCulture); @@ -68,7 +68,7 @@ public PrivateType(Type type) => /// Invokes static member. /// /// Name of the member to InvokeHelper. - /// An array of objects representing the number, order, and type of the parameters for the method to invoke. + /// An array of objects representing the number, order, and type of the parameters for the method to invoke. /// Arguments to the invocation. /// An array of types corresponding to the types of the generic arguments. /// Result of invocation. @@ -87,7 +87,7 @@ public PrivateType(Type type) => /// Invokes the static method. /// /// Name of the member. - /// An array of objects representing the number, order, and type of the parameters for the method to invoke. + /// An array of objects representing the number, order, and type of the parameters for the method to invoke. /// Arguments to the invocation. /// Culture info. /// Result of invocation. @@ -107,7 +107,7 @@ public PrivateType(Type type) => /// /// Name of the member. /// Additional invocation attributes. - /// An array of objects representing the number, order, and type of the parameters for the method to invoke. + /// An array of objects representing the number, order, and type of the parameters for the method to invoke. /// Arguments to the invocation. /// Result of invocation. public object InvokeStatic(string name, BindingFlags bindingFlags, Type[]? parameterTypes, object?[]? args) => InvokeStatic(name, bindingFlags, parameterTypes, args, CultureInfo.InvariantCulture); @@ -127,7 +127,7 @@ public PrivateType(Type type) => /// /// Name of the member. /// Additional invocation attributes. - /// /// An array of objects representing the number, order, and type of the parameters for the method to invoke. + /// /// An array of objects representing the number, order, and type of the parameters for the method to invoke. /// Arguments to the invocation. /// Culture. /// Result of invocation. @@ -138,7 +138,7 @@ public PrivateType(Type type) => /// /// Name of the member. /// Additional invocation attributes. - /// /// An array of objects representing the number, order, and type of the parameters for the method to invoke. + /// /// An array of objects representing the number, order, and type of the parameters for the method to invoke. /// Arguments to the invocation. /// Culture. /// An array of types corresponding to the types of the generic arguments. @@ -354,7 +354,7 @@ public void SetStaticFieldOrProperty(string name, BindingFlags bindingFlags, obj /// /// Name of the property. /// Value to be set to field or property. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// Arguments to pass to the member to invoke. public void SetStaticProperty(string name, object value, Type[]? parameterTypes, object?[]? args) => SetStaticProperty(name, BindingFlags.SetProperty, value, parameterTypes, args); @@ -372,7 +372,7 @@ public void SetStaticFieldOrProperty(string name, BindingFlags bindingFlags, obj /// /// Name of the property. /// Additional invocation attributes. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// Arguments to pass to the member to invoke. /// The static property. public object GetStaticProperty(string name, BindingFlags bindingFlags, Type[]? parameterTypes, object?[]? args) @@ -403,7 +403,7 @@ public object GetStaticProperty(string name, BindingFlags bindingFlags, Type[]? /// Name of the property. /// Additional invocation attributes. /// Value to be set to field or property. - /// An array of objects representing the number, order, and type of the parameters for the indexed property. + /// An array of objects representing the number, order, and type of the parameters for the indexed property. /// Arguments to pass to the member to invoke. public void SetStaticProperty(string name, BindingFlags bindingFlags, object value, Type[]? parameterTypes, object?[]? args) { diff --git a/src/TestFramework/TestFramework.Extensions/TestContext.cs b/src/TestFramework/TestFramework.Extensions/TestContext.cs index 95f08dcde9..83082db374 100644 --- a/src/TestFramework/TestFramework.Extensions/TestContext.cs +++ b/src/TestFramework/TestFramework.Extensions/TestContext.cs @@ -206,7 +206,7 @@ public abstract class TestContext { DebugEx.Assert(Properties is not null, "Properties is null"); #if WINDOWS_UWP || WIN_UI - if (!((System.Collections.Generic.IDictionary)Properties).TryGetValue(name, out object? propertyValue)) + if (!((IDictionary)Properties).TryGetValue(name, out object? propertyValue)) { return null; } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index b8b2831400..d186f6721b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -16,7 +16,7 @@ public sealed partial class Assert /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -36,7 +36,7 @@ public static void AreEqual(T? expected, T? actual) /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -48,8 +48,8 @@ public static void AreEqual(T? expected, T? actual) /// The second value to compare. This is the value produced by the code under test. /// /// - /// The implementation to use when comparing keys, - /// or null to use the default . + /// The implementation to use when comparing keys, + /// or null to use the default . /// /// /// Thrown if is not equal to . @@ -60,7 +60,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -98,8 +98,8 @@ public static void AreEqual(T? expected, T? actual, string? message) /// The second value to compare. This is the value produced by the code under test. /// /// - /// The implementation to use when comparing keys, - /// or null to use the default . + /// The implementation to use when comparing keys, + /// or null to use the default . /// /// /// The message to include in the exception when @@ -116,7 +116,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -157,8 +157,8 @@ public static void AreEqual(T? expected, T? actual, [StringSyntax(StringSynta /// The second value to compare. This is the value produced by the code under test. /// /// - /// The implementation to use when comparing keys, - /// or null to use the default . + /// The implementation to use when comparing keys, + /// or null to use the default . /// /// /// The message to include in the exception when @@ -204,7 +204,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer? com /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -224,7 +224,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual) /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -250,7 +250,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, s /// /// Tests whether the specified values are equal and throws an exception /// if the two values are not equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -308,7 +308,7 @@ public static void AreEqual(IEquatable? expected, IEquatable? actual, [ /// /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -342,8 +342,8 @@ public static void AreNotEqual(T? notExpected, T? actual) /// The second value to compare. This is the value produced by the code under test. /// /// - /// The implementation to use when comparing keys, - /// or null to use the default . + /// The implementation to use when comparing keys, + /// or null to use the default . /// /// /// Thrown if is equal to . @@ -354,7 +354,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -393,8 +393,8 @@ public static void AreNotEqual(T? notExpected, T? actual, string? message) /// The second value to compare. This is the value produced by the code under test. /// /// - /// The implementation to use when comparing keys, - /// or null to use the default . + /// The implementation to use when comparing keys, + /// or null to use the default . /// /// /// The message to include in the exception when @@ -410,7 +410,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer /// Tests whether the specified values are unequal and throws an exception /// if the two values are equal. - /// The equality is computed using the default . + /// The equality is computed using the default . /// /// /// The type of values to compare. @@ -452,8 +452,8 @@ public static void AreNotEqual(T? notExpected, T? actual, [StringSyntax(Strin /// The second value to compare. This is the value produced by the code under test. /// /// - /// The implementation to use when comparing keys, - /// or null to use the default . + /// The implementation to use when comparing keys, + /// or null to use the default . /// /// /// The message to include in the exception when diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 81fe910c6c..81392a5742 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -48,7 +48,7 @@ public static void IsInstanceOfType([NotNull] object? value) /// /// The expected type of . public static void IsInstanceOfType([NotNull] object? value, out T instance) - => IsInstanceOfType(value, out instance, string.Empty, null); + => IsInstanceOfType(value, out instance, string.Empty, null); /// /// Tests whether the specified object is an instance of the expected @@ -90,7 +90,7 @@ public static void IsInstanceOfType([NotNull] object? value, string? message) /// /// The expected type of . public static void IsInstanceOfType([NotNull] object? value, out T instance, string? message) - => IsInstanceOfType(value, out instance, message, null); + => IsInstanceOfType(value, out instance, message, null); /// /// Tests whether the specified object is an instance of the expected diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index 98d779210f..bf76e223d5 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -1563,8 +1563,8 @@ private static bool FindMismatchedElement(IEnumerable expected, IEnumerab // $ CONSIDER: comparison, which should result in ~n*log(n) + m*log(m) + n. // Count the occurrences of each object in the both collections - Dictionary expectedElements = GetElementCounts(expected, comparer, out int expectedNulls); - Dictionary actualElements = GetElementCounts(actual, comparer, out int actualNulls); + Dictionary expectedElements = GetElementCounts(expected, comparer, out int expectedNulls); + Dictionary actualElements = GetElementCounts(actual, comparer, out int actualNulls); if (actualNulls != expectedNulls) { diff --git a/src/TestFramework/TestFramework/Attributes/DataSource/DataSourceAttribute.cs b/src/TestFramework/TestFramework/Attributes/DataSource/DataSourceAttribute.cs index b23dec0cab..ac30e26910 100644 --- a/src/TestFramework/TestFramework/Attributes/DataSource/DataSourceAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/DataSource/DataSourceAttribute.cs @@ -105,7 +105,7 @@ public DataSourceAttribute(string connectionString, string tableName) /// /// /// - /// One of the values. If the is not initialized, this will return the default value . + /// One of the values. If the is not initialized, this will return the default value . /// public DataAccessMethod DataAccessMethod { get; } diff --git a/test/.editorconfig b/test/.editorconfig index 26a155ee3a..f7922ee56d 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -29,3 +29,10 @@ dotnet_diagnostic.CA2201.severity = none # CA2201: Do not raise reser dotnet_diagnostic.CA3075.severity = none # CA3075: Insecure DTD processing in XML dotnet_diagnostic.IDE0060.severity = none # IDE0060: Remove unused parameter + +dotnet_diagnostic.MSTEST0001.severity = warning # MSTEST0001: Explicitly enable or disable tests parallelization +dotnet_diagnostic.MSTEST0016.severity = warning # MSTEST0016: Test class should have test method +dotnet_diagnostic.MSTEST0017.severity = warning # MSTEST0017: Assertion arguments should be passed in the correct order +dotnet_diagnostic.MSTEST0029.severity = warning # MSTEST0029: Public methods should be test methods +dotnet_diagnostic.MSTEST0030.severity = warning # MSTEST0030: Type containing '[TestMethod]' should be marked with '[TestClass]' +dotnet_diagnostic.MSTEST0032.severity = warning # MSTEST0032: Assertion condition is always true diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets index 9f0a8ac53b..be7e8c4711 100644 --- a/test/Directory.Build.targets +++ b/test/Directory.Build.targets @@ -6,8 +6,9 @@ enable Exe - + true false + false $(PlatformTarget) x64 $(MSBuildProjectName)_$(TargetFramework)_$(Configuration)_$(Architecture) @@ -22,22 +23,20 @@ - - - - - - + + + + - + diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AbortionTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AbortionTests.cs index a96340353a..e8130111cc 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AbortionTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AbortionTests.cs @@ -9,16 +9,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class AbortionTests : AcceptanceTestBase +[TestClass] +public sealed class AbortionTests : AcceptanceTestBase { private const string AssetName = "Abort"; - private readonly TestAssetFixture _testAssetFixture; - - public AbortionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AbortWithCTRLPlusC_CancellingTests(string tfm) { // We expect the same semantic for Linux, the test setup is not cross and we're using specific @@ -28,7 +25,7 @@ public async Task AbortWithCTRLPlusC_CancellingTests(string tfm) return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); string fileCreationPath = Path.Combine(testHost.DirectoryName, "fileCreation"); File.WriteAllText(fileCreationPath, string.Empty); @@ -43,8 +40,7 @@ public async Task AbortWithCTRLPlusC_CancellingTests(string tfm) testHostResult.AssertOutputMatchesRegex("Canceling the test session.*"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string Sources = """ #file Abort.csproj diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolutionTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolutionTests.cs index 780b689d78..1cad3bfabc 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolutionTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolutionTests.cs @@ -6,17 +6,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class AssemblyResolutionTests : AcceptanceTestBase +[TestClass] +public sealed class AssemblyResolutionTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public AssemblyResolutionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task AssemblyResolution_WhenNotSpecified_TestFails() { - TestHostResult testHostResult = await _testAssetFixture.TestHost.ExecuteAsync(); + TestHostResult testHostResult = await AssetFixture.TestHost.ExecuteAsync(); // Assert testHostResult.AssertExitCodeIs(2); @@ -24,10 +20,11 @@ public async Task AssemblyResolution_WhenNotSpecified_TestFails() testHostResult.AssertOutputContainsSummary(failed: 1, passed: 0, skipped: 0); } + [TestMethod] public async Task AssemblyResolution_WhenSpecified_TestSucceeds() { // Arrange - string runSettingsFilePath = Path.Combine(_testAssetFixture.TestHost.DirectoryName, ".runsettings"); + string runSettingsFilePath = Path.Combine(AssetFixture.TestHost.DirectoryName, ".runsettings"); File.WriteAllText(runSettingsFilePath, $""" @@ -35,14 +32,14 @@ public async Task AssemblyResolution_WhenSpecified_TestSucceeds() - + """); // Act - TestHostResult testHostResult = await _testAssetFixture.TestHost.ExecuteAsync($"--settings {runSettingsFilePath}"); + TestHostResult testHostResult = await AssetFixture.TestHost.ExecuteAsync($"--settings {runSettingsFilePath}"); // Assert testHostResult.AssertExitCodeIs(0); @@ -50,12 +47,11 @@ public async Task AssemblyResolution_WhenSpecified_TestSucceeds() testHostResult.AssertOutputDoesNotContain("System.IO.FileNotFoundException: Could not load file or assembly 'MSTest.Extensibility.Samples"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : IAsyncInitializable, IDisposable + public sealed class TestAssetFixture : ITestAssetFixture { public const string ProjectName = "AssemblyResolution.Main"; private const string TestProjectName = "AssemblyResolution.Test"; - private static readonly string TargetFramework = TargetFrameworks.NetCurrent.Arguments; + private static readonly string TargetFramework = TargetFrameworks.NetCurrent; private readonly TempDirectory _testAssetDirectory = new(); @@ -69,10 +65,10 @@ public void Dispose() MainDllFolder?.Dispose(); } - public async Task InitializeAsync(InitializationContext context) + public async Task InitializeAsync() { VSSolution solution = CreateTestAsset(); - DotnetMuxerResult result = await DotnetCli.RunAsync($"build -nodeReuse:false {solution.SolutionFile} -c Release", acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult result = await DotnetCli.RunAsync($"build -nodeReuse:false {solution.SolutionFile} -c Release", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, result.ExitCode); TestHost = TestHost.LocateFrom(solution.Projects.Skip(1).Single().FolderPath, TestProjectName, TargetFramework); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolverTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolverTests.cs index 993d5393b7..cf839e1f41 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolverTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/AssemblyResolverTests.cs @@ -7,17 +7,12 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class AssemblyResolverTests : AcceptanceTestBase +[TestClass] +public class AssemblyResolverTests : AcceptanceTestBase { private const string AssetName = "AssemblyResolverCrash"; - private readonly TestAssetFixture _testAssetFixture; - - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public AssemblyResolverTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; + [TestMethod] public async Task RunningTests_DoesNotHitResourceRecursionIssueAndDoesNotCrashTheRunner() { if (!OperatingSystem.IsWindows()) @@ -26,15 +21,14 @@ public async Task RunningTests_DoesNotHitResourceRecursionIssueAndDoesNotCrashTh return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetFramework[0].Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetFramework[0]); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.Success); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string TargetAssetPath => GetAssetPath(AssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CancellationTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CancellationTests.cs index bab603e279..6bc078f8eb 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CancellationTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CancellationTests.cs @@ -6,17 +6,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class CancellationTests : AcceptanceTestBase +[TestClass] +public sealed class CancellationTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public CancellationTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task WhenCancelingTestContextTokenInAssemblyInit_MessageIsAsExpected() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { ["ASSEMBLYINIT_CANCEL"] = "1", @@ -28,9 +24,10 @@ public async Task WhenCancelingTestContextTokenInAssemblyInit_MessageIsAsExpecte testHostResult.AssertOutputContains("Failed!"); } + [TestMethod] public async Task WhenCancelingTestContextTokenInClassInit_MessageIsAsExpected() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { ["CLASSINIT_CANCEL"] = "1", @@ -42,9 +39,10 @@ public async Task WhenCancelingTestContextTokenInClassInit_MessageIsAsExpected() testHostResult.AssertOutputContains("Failed!"); } + [TestMethod] public async Task WhenCancelingTestContextTokenInTestInit_MessageIsAsExpected() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { ["TESTINIT_CANCEL"] = "1", @@ -56,9 +54,10 @@ public async Task WhenCancelingTestContextTokenInTestInit_MessageIsAsExpected() testHostResult.AssertOutputContains("Failed!"); } + [TestMethod] public async Task WhenCancelingTestContextTokenInTestCleanup_MessageIsAsExpected() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { ["TESTCLEANUP_CANCEL"] = "1", @@ -70,9 +69,10 @@ public async Task WhenCancelingTestContextTokenInTestCleanup_MessageIsAsExpected testHostResult.AssertOutputContains("Failed!"); } + [TestMethod] public async Task WhenCancelingTestContextTokenInTestMethod_MessageIsAsExpected() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { ["TESTMETHOD_CANCEL"] = "1", @@ -84,8 +84,7 @@ public async Task WhenCancelingTestContextTokenInTestMethod_MessageIsAsExpected( testHostResult.AssertOutputContains("Failed!"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestCancellation"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ConfigurationSettingsTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ConfigurationSettingsTests.cs index 1ff51d33a8..8637871e8b 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ConfigurationSettingsTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ConfigurationSettingsTests.cs @@ -7,18 +7,14 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class ConfigurationSettingsTests : AcceptanceTestBase +[TestClass] +public sealed class ConfigurationSettingsTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public ConfigurationSettingsTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestConfigJson_AndRunSettingsHasMstest_Throws(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPathWithMSTestRunSettings, TestAssetFixture.ProjectNameWithMSTestRunSettings, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPathWithMSTestRunSettings, TestAssetFixture.ProjectNameWithMSTestRunSettings, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings"); // Assert @@ -26,10 +22,11 @@ public async Task TestConfigJson_AndRunSettingsHasMstest_Throws(string tfm) testHostResult.AssertStandardErrorContains("Both '.runsettings' and '.testconfig.json' files have been detected. Please select only one of these test configuration files."); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestConfigJson_AndRunSettingsHasMstestv2_Throws(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPathWithMSTestV2RunSettings, TestAssetFixture.ProjectNameWithMSTestV2RunSettings, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPathWithMSTestV2RunSettings, TestAssetFixture.ProjectNameWithMSTestV2RunSettings, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings"); // Assert @@ -37,29 +34,32 @@ public async Task TestConfigJson_AndRunSettingsHasMstestv2_Throws(string tfm) testHostResult.AssertStandardErrorContains("Both '.runsettings' and '.testconfig.json' files have been detected. Please select only one of these test configuration files."); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestConfigJson_AndRunSettingsWithoutMstest_OverrideRunConfigration(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings"); // Assert testHostResult.AssertExitCodeIs(ExitCodes.Success); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestConfigJson_WithoutRunSettings_BuildSuccess(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); // Assert testHostResult.AssertExitCodeIs(ExitCodes.Success); } + [TestMethod] public async Task TestWithConfigFromCommandLineWithMapInconclusiveToFailedIsTrue() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--config-file dummyconfigfile_map.json", environmentVariables: new() { ["TestWithConfigFromCommandLine"] = "true", @@ -69,9 +69,10 @@ public async Task TestWithConfigFromCommandLineWithMapInconclusiveToFailedIsTrue testHostResult.AssertOutputContainsSummary(failed: 1, passed: 1, skipped: 0); } + [TestMethod] public async Task TestWithConfigFromCommandLineWithMapInconclusiveToFailedIsFalse() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--config-file dummyconfigfile_doNotMap.json", environmentVariables: new() { ["TestWithConfigFromCommandLine"] = "true", @@ -81,9 +82,10 @@ public async Task TestWithConfigFromCommandLineWithMapInconclusiveToFailedIsFals testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 1); } + [TestMethod] public async Task TestWithConfigFromCommandLineWithNonExistingFile() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--config-file dummyconfigfile_not_existing_file.json", environmentVariables: new() { ["TestWithConfigFromCommandLine"] = "true", @@ -93,8 +95,7 @@ public async Task TestWithConfigFromCommandLineWithNonExistingFile() testHostResult.AssertStandardErrorContains("dummyconfigfile_not_existing_file.json"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "ConfigurationSettings"; public const string ProjectNameWithMSTestRunSettings = "ConfigurationMSTestSettings"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DataSourceTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DataSourceTests.cs index 375dedad5f..f3ea941e28 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DataSourceTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DataSourceTests.cs @@ -7,8 +7,8 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class DataSourceTests : AcceptanceTestBase +[TestClass] +public sealed class DataSourceTests : AcceptanceTestBase { private const string SourceCode = """ #file DataSourceTests.csproj @@ -83,11 +83,7 @@ public void MyTest() 1,1,1 """; - private readonly AcceptanceFixture _acceptanceFixture; - - public DataSourceTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - + [TestMethod] public async Task TestDataSourceFromAppConfig() { if (!OperatingSystem.IsWindows()) @@ -105,7 +101,7 @@ public async Task TestDataSourceFromAppConfig() await DotnetCli.RunAsync( $"build {generator.TargetAssetPath} -c Release", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, retryCount: 0); var testHost = TestHost.LocateFrom(generator.TargetAssetPath, "DataSourceTests", "net472"); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DotnetTestCliTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DotnetTestCliTests.cs index 3bed38780c..85a3cc1970 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DotnetTestCliTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/DotnetTestCliTests.cs @@ -6,16 +6,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class DotnetTestCliTests : AcceptanceTestBase +[TestClass] +public class DotnetTestCliTests : AcceptanceTestBase { private const string AssetName = "MSTestProject"; - private readonly AcceptanceFixture _acceptanceFixture; - public DotnetTestCliTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixTfmBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task DotnetTest_Should_Execute_Tests(string tfm, BuildConfiguration buildConfiguration) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -28,9 +25,9 @@ public async Task DotnetTest_Should_Execute_Tests(string tfm, BuildConfiguration .PatchCodeWithReplace("$OutputType$", string.Empty) .PatchCodeWithReplace("$Extra$", string.Empty)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -m:1 -nodeReuse:false {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -m:1 -nodeReuse:false {generator.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); // There is whitespace difference in output in parent and public repo that depends on the version of the dotnet SDK used. - compilationResult.AssertOutputRegEx(@"Passed!\s+-\s+Failed:\s+0,\s+Passed:\s+1,\s+Skipped:\s+0,\s+Total:\s+1"); + compilationResult.AssertOutputMatchesRegex(@"Passed!\s+-\s+Failed:\s+0,\s+Passed:\s+1,\s+Skipped:\s+0,\s+Total:\s+1"); } } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs index a65b1d9827..ef0053229a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs @@ -9,19 +9,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class GenericTestMethodTests : AcceptanceTestBase +[TestClass] +public class GenericTestMethodTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public GenericTestMethodTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task TestDifferentGenericMethodTestCases() { - var testHost = TestHost.LocateFrom(_testAssetFixture.GetAssetPath("GenericTestMethodTests"), "GenericTestMethodTests", TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.GetAssetPath("GenericTestMethodTests"), "GenericTestMethodTests", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(); @@ -75,8 +69,7 @@ at .+? """, RegexOptions.Singleline); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public override IEnumerable<(string ID, string Name, string Code)> GetAssetsToGenerate() { diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs index e64b0928f5..d43193af01 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -7,21 +7,16 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class HelpInfoTests : AcceptanceTestBase +[TestClass] +public class HelpInfoTests : AcceptanceTestBase { private const string AssetName = "HelpInfo"; - private readonly TestAssetFixture _testAssetFixture; - - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public HelpInfoTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task Help_WhenMSTestExtensionRegistered_OutputHelpContentOfRegisteredExtension(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--help"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -89,10 +84,11 @@ Output verbosity when reporting tests. testHostResult.AssertOutputMatchesLines(wildcardMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task Info_WhenMSTestExtensionRegistered_OutputInfoContentOfRegisteredExtension(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--info"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -124,8 +120,7 @@ public async Task Info_WhenMSTestExtensionRegistered_OutputInfoContentOfRegister testHostResult.AssertOutputContains(output); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string TargetAssetPath => GetAssetPath(AssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/IgnoreTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/IgnoreTests.cs index 40815c38f3..74d6740d73 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/IgnoreTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/IgnoreTests.cs @@ -6,17 +6,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class IgnoreTests : AcceptanceTestBase +[TestClass] +public sealed class IgnoreTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public IgnoreTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task ClassCleanup_Inheritance_WhenClassIsSkipped() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings --filter ClassName!~TestClassWithAssemblyInitialize"); // Assert @@ -26,9 +22,10 @@ public async Task ClassCleanup_Inheritance_WhenClassIsSkipped() testHostResult.AssertOutputContains("SubClass.Method"); } + [TestMethod] public async Task WhenAllTestsAreIgnored_AssemblyInitializeAndCleanupAreSkipped() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings --filter TestClassWithAssemblyInitialize"); // Assert @@ -38,8 +35,7 @@ public async Task WhenAllTestsAreIgnored_AssemblyInitializeAndCleanupAreSkipped( testHostResult.AssertOutputDoesNotContain("AssemblyCleanup"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestIgnore"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/InitializeAndCleanupTimeoutTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/InitializeAndCleanupTimeoutTests.cs index 46a0a47ec4..2a78f7726f 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/InitializeAndCleanupTimeoutTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/InitializeAndCleanupTimeoutTests.cs @@ -8,8 +8,8 @@ namespace MSTest.Acceptance.IntegrationTests; -// [TestGroup] -public class InitializeAndCleanupTimeoutTests : AcceptanceTestBase +[TestClass] +public class InitializeAndCleanupTimeoutTests : AcceptanceTestBase { private static readonly Dictionary InfoByKind = new() { @@ -23,151 +23,175 @@ public class InitializeAndCleanupTimeoutTests : AcceptanceTestBase ["testCleanup"] = ("TestClass.TestCleanupMethod", "Test cleanup", "TESTCLEANUP", "TestCleanupTimeout"), }; - private readonly TestAssetFixture _testAssetFixture; - - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public InitializeAndCleanupTimeoutTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyInit_WhenTestContextCanceled_AssemblyInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestWasCanceledAsync(_testAssetFixture.CodeWithSixtySecTimeoutAssetPath, TestAssetFixture.CodeWithSixtySecTimeout, + => await RunAndAssertTestWasCanceledAsync(AssetFixture.CodeWithSixtySecTimeoutAssetPath, TestAssetFixture.CodeWithSixtySecTimeout, tfm, "TESTCONTEXT_CANCEL_", "assemblyInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyInit_WhenTimeoutExpires_AssemblyInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "assemblyInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyInit_WhenTimeoutExpiresAndTestContextTokenIsUsed_AssemblyInitializeExits(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "TIMEOUT_", "assemblyInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInit_WhenTestContextCanceled_ClassInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestWasCanceledAsync(_testAssetFixture.CodeWithSixtySecTimeoutAssetPath, TestAssetFixture.CodeWithSixtySecTimeout, tfm, + => await RunAndAssertTestWasCanceledAsync(AssetFixture.CodeWithSixtySecTimeoutAssetPath, TestAssetFixture.CodeWithSixtySecTimeout, tfm, "TESTCONTEXT_CANCEL_", "classInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInit_WhenTimeoutExpires_ClassInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "classInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInit_WhenTimeoutExpiresAndTestContextTokenIsUsed_ClassInitializeExits(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "TIMEOUT_", "classInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInitBase_WhenTestContextCanceled_ClassInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestWasCanceledAsync(_testAssetFixture.CodeWithSixtySecTimeoutAssetPath, TestAssetFixture.CodeWithSixtySecTimeout, tfm, + => await RunAndAssertTestWasCanceledAsync(AssetFixture.CodeWithSixtySecTimeoutAssetPath, TestAssetFixture.CodeWithSixtySecTimeout, tfm, "TESTCONTEXT_CANCEL_", "baseClassInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInitBase_WhenTimeoutExpires_ClassInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "baseClassInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInitBase_WhenTimeoutExpiresAndTestContextTokenIsUsed_ClassInitializeExits(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "TIMEOUT_", "baseClassInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyInitialize_WhenTimeoutExpires_FromRunSettings_AssemblyInitializeIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "assemblyInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInitialize_WhenTimeoutExpires_FromRunSettings_ClassInitializeIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "classInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task BaseClassInitialize_WhenTimeoutExpires_FromRunSettings_ClassInitializeIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "baseClassInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyInitialize_WhenTimeoutExpires_AssemblyInitializeIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "assemblyInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassInitialize_WhenTimeoutExpires_ClassInitializeIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "classInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task BaseClassInitialize_WhenTimeoutExpires_ClassInitializeIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "baseClassInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassCleanupBase_WhenTimeoutExpires_ClassCleanupTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "baseClassCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassCleanup_WhenTimeoutExpires_ClassCleanupTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "classCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassCleanup_WhenTimeoutExpires_FromRunSettings_ClassCleanupIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "classCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task BaseClassCleanup_WhenTimeoutExpires_FromRunSettings_ClassCleanupIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "baseClassCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ClassCleanup_WhenTimeoutExpires_ClassCleanupIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "classCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task BaseClassCleanup_WhenTimeoutExpires_ClassCleanupIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "baseClassCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyCleanup_WhenTimeoutExpires_AssemblyCleanupTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "assemblyCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyCleanup_WhenTimeoutExpires_FromRunSettings_AssemblyCleanupIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "assemblyCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task AssemblyCleanup_WhenTimeoutExpires_AssemblyCleanupIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "assemblyCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestInitialize_WhenTimeoutExpires_TestInitializeTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "testInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestInitialize_WhenTimeoutExpires_FromRunSettings_TestInitializeIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "testInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestInitialize_WhenTimeoutExpires_TestInitializeIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "testInit"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestCleanup_WhenTimeoutExpires_TestCleanupTaskIsCanceled(string tfm) - => await RunAndAssertTestTimedOutAsync(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, + => await RunAndAssertTestTimedOutAsync(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm, "LONG_WAIT_", "testCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestCleanup_WhenTimeoutExpires_FromRunSettings_TestCleanupIsCanceled(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 300, false, "testCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestCleanup_WhenTimeoutExpires_TestCleanupIsCanceled_AttributeTakesPrecedence(string tfm) => await RunAndAssertWithRunSettingsAsync(tfm, 25000, true, "testCleanup"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenAssemblyInitTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_ASSEMBLYINIT"] = "1" }); @@ -178,10 +202,11 @@ public async Task CooperativeCancellation_WhenAssemblyInitTimeoutExpires_StepThr testHostResult.AssertOutputDoesNotContain("AssemblyInit completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenAssemblyCleanupTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_ASSEMBLYCLEANUP"] = "1" }); @@ -192,10 +217,11 @@ public async Task CooperativeCancellation_WhenAssemblyCleanupTimeoutExpires_Step testHostResult.AssertOutputDoesNotContain("AssemblyCleanup completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenClassInitTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_CLASSINIT"] = "1" }); @@ -206,10 +232,11 @@ public async Task CooperativeCancellation_WhenClassInitTimeoutExpires_StepThrows testHostResult.AssertOutputDoesNotContain("ClassInit completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenClassCleanupTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_CLASSCLEANUP"] = "1" }); @@ -220,10 +247,11 @@ public async Task CooperativeCancellation_WhenClassCleanupTimeoutExpires_StepThr testHostResult.AssertOutputDoesNotContain("ClassCleanup completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenTestInitTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_TESTINIT"] = "1" }); @@ -233,10 +261,11 @@ public async Task CooperativeCancellation_WhenTestInitTimeoutExpires_StepThrows( testHostResult.AssertOutputDoesNotContain("TestInit completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenTestCleanupTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_TESTCLEANUP"] = "1" }); @@ -246,10 +275,11 @@ public async Task CooperativeCancellation_WhenTestCleanupTimeoutExpires_StepThro testHostResult.AssertOutputDoesNotContain("TestCleanup completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenTestMethodTimeoutExpires_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["TASKDELAY_TESTMETHOD"] = "1" }); @@ -259,10 +289,11 @@ public async Task CooperativeCancellation_WhenTestMethodTimeoutExpires_StepThrow testHostResult.AssertOutputDoesNotContain("TestMethod completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenAssemblyInitTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_ASSEMBLYINIT"] = "1" }); @@ -273,10 +304,11 @@ public async Task CooperativeCancellation_WhenAssemblyInitTimeoutExpiresAndUserC testHostResult.AssertOutputDoesNotContain("AssemblyInit completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenAssemblyCleanupTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_ASSEMBLYCLEANUP"] = "1" }); @@ -287,10 +319,11 @@ public async Task CooperativeCancellation_WhenAssemblyCleanupTimeoutExpiresAndUs testHostResult.AssertOutputDoesNotContain("AssemblyCleanup completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenClassInitTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_CLASSINIT"] = "1" }); @@ -301,10 +334,11 @@ public async Task CooperativeCancellation_WhenClassInitTimeoutExpiresAndUserChec testHostResult.AssertOutputDoesNotContain("ClassInit completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenClassCleanupTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_CLASSCLEANUP"] = "1" }); @@ -315,10 +349,11 @@ public async Task CooperativeCancellation_WhenClassCleanupTimeoutExpiresAndUserC testHostResult.AssertOutputDoesNotContain("ClassCleanup completed"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenTestInitTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_TESTINIT"] = "1" }); @@ -328,10 +363,11 @@ public async Task CooperativeCancellation_WhenTestInitTimeoutExpiresAndUserCheck testHostResult.AssertOutputContains("Test initialize method 'TestClass.TestInit' timed out"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenTestCleanupTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_TESTCLEANUP"] = "1" }); @@ -341,10 +377,11 @@ public async Task CooperativeCancellation_WhenTestCleanupTimeoutExpiresAndUserCh testHostResult.AssertOutputContains("Test cleanup method 'TestClass.TestCleanup' timed out"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CooperativeCancellation_WhenTestMethodTimeoutExpiresAndUserChecksToken_StepThrows(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutAssetPath, TestAssetFixture.CooperativeTimeout, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--settings my.runsettings", new() { ["CHECKTOKEN_TESTMETHOD"] = "1" }); @@ -385,8 +422,8 @@ private async Task RunAndAssertWithRunSettingsAsync(string tfm, int timeoutValue timeoutValue = assertAttributePrecedence ? 1000 : timeoutValue; TestHost testHost = assertAttributePrecedence - ? TestHost.LocateFrom(_testAssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm) - : TestHost.LocateFrom(_testAssetFixture.CodeWithNoTimeoutAssetPath, TestAssetFixture.CodeWithNoTimeout, tfm); + ? TestHost.LocateFrom(AssetFixture.CodeWithOneSecTimeoutAssetPath, TestAssetFixture.CodeWithOneSecTimeout, tfm) + : TestHost.LocateFrom(AssetFixture.CodeWithNoTimeoutAssetPath, TestAssetFixture.CodeWithNoTimeout, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, $"{Guid.NewGuid():N}.runsettings"); File.WriteAllText(runSettingsFilePath, runSettings); @@ -402,8 +439,7 @@ private async Task RunAndAssertWithRunSettingsAsync(string tfm, int timeoutValue testHostResult.AssertOutputContains($"{InfoByKind[entryKind].Prefix} method '{InfoByKind[entryKind].MethodFullName}' timed out after {timeoutValue}ms"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string CodeWithOneSecTimeout = nameof(CodeWithOneSecTimeout); public const string CodeWithSixtySecTimeout = nameof(CodeWithSixtySecTimeout); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSBuildRunnerTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSBuildRunnerTests.cs index 8cb7d672e8..770b7eb021 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSBuildRunnerTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSBuildRunnerTests.cs @@ -6,19 +6,15 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class MSBuildRunnerTests : AcceptanceTestBase +[TestClass] +public class MSBuildRunnerTests : AcceptanceTestBase { private const string AssetName = "MSTestProject"; private const string DotnetTestVerb = "test"; - private readonly AcceptanceFixture _acceptanceFixture; - public MSBuildRunnerTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - internal static IEnumerable> GetBuildMatrix() + internal static IEnumerable<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm, string Command)> GetBuildMatrix() { - foreach (TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm)> entry in GetBuildMatrixSingleAndMultiTfmBuildConfiguration()) + foreach ((string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm) entry in GetBuildMatrixSingleAndMultiTfmBuildConfiguration()) { foreach (string command in new string[] { @@ -26,13 +22,13 @@ public MSBuildRunnerTests(ITestExecutionContext testExecutionContext, Acceptance DotnetTestVerb, }) { - yield return new TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm, string Command)>( - (entry.Arguments.SingleTfmOrMultiTfm, entry.Arguments.BuildConfiguration, entry.Arguments.IsMultiTfm, command), $"{(entry.Arguments.IsMultiTfm ? "multitfm" : entry.Arguments.SingleTfmOrMultiTfm)},{entry.Arguments.BuildConfiguration},{command}"); + yield return new(entry.SingleTfmOrMultiTfm, entry.BuildConfiguration, entry.IsMultiTfm, command); } } } - [ArgumentsProvider(nameof(GetBuildMatrix))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method)] public async Task MSBuildTestTarget_SingleAndMultiTfm_Should_Run_Solution_Tests(string singleTfmOrMultiTfm, BuildConfiguration buildConfiguration, bool isMultiTfm, string command) { // Get the template project @@ -68,24 +64,24 @@ public async Task MSBuildTestTarget_SingleAndMultiTfm_Should_Run_Solution_Tests( } // Build the solution - DotnetMuxerResult restoreResult = await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {solution.SolutionFile} --configfile {nugetFile}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); - restoreResult.AssertOutputNotContains("An approximate best match of"); - DotnetMuxerResult testResult = await DotnetCli.RunAsync($"{command} -m:1 -nodeReuse:false {solution.SolutionFile}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult restoreResult = await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {solution.SolutionFile} --configfile {nugetFile}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); + restoreResult.AssertOutputDoesNotContain("An approximate best match of"); + DotnetMuxerResult testResult = await DotnetCli.RunAsync($"{command} -m:1 -nodeReuse:false {solution.SolutionFile}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); if (isMultiTfm) { foreach (string tfm in singleTfmOrMultiTfm.Split(';')) { - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject0\..*' \[{tfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject1\..*' \[{tfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject2\..*' \[{tfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject0\..*' \[{tfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject1\..*' \[{tfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject2\..*' \[{tfm}\|x64\]"); } } else { - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject0\..*' \[{singleTfmOrMultiTfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject1\..*' \[{singleTfmOrMultiTfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject2\..*' \[{singleTfmOrMultiTfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject0\..*' \[{singleTfmOrMultiTfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject1\..*' \[{singleTfmOrMultiTfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject2\..*' \[{singleTfmOrMultiTfm}\|x64\]"); } } } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj index 06e198a550..b204fdef59 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj @@ -3,6 +3,7 @@ $(NetCurrent) false + true $(DefineConstants);SKIP_INTERMEDIATE_TARGET_FRAMEWORKS Exe true diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs index 9c5f2fe087..fe3753fae4 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs @@ -10,19 +10,16 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class MaxFailedTestsExtensionTests : AcceptanceTestBase +[TestClass] +public sealed class MaxFailedTestsExtensionTests : AcceptanceTestBase { private const string AssetName = nameof(MaxFailedTestsExtensionTests); - private readonly TestAssetFixture _testAssetFixture; - - public MaxFailedTestsExtensionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SimpleMaxFailedTestsScenario(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--maximum-failed-tests 3"); testHostResult.AssertExitCodeIs(ExitCodes.TestExecutionStoppedForMaxFailedTests); @@ -42,8 +39,7 @@ public async Task SimpleMaxFailedTestsScenario(string tfm) Assert.AreEqual(12, total); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string Sources = """ #file MaxFailedTestsExtensionTests.csproj diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/NativeAotTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/NativeAotTests.cs index 59dcb83da2..fb0cf271af 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/NativeAotTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/NativeAotTests.cs @@ -8,8 +8,8 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class NativeAotTests : AcceptanceTestBase +[TestClass] +public class NativeAotTests : AcceptanceTestBase { private const string SourceCode = """ #file NativeAotTests.csproj @@ -84,11 +84,7 @@ public void TestMethod3(int a, int b) } """; - private readonly AcceptanceFixture _acceptanceFixture; - - public NativeAotTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - + [TestMethod] public async Task NativeAotTests_WillRunWithExitCodeZero() { // The hosted AzDO agents for Mac OS don't have the required tooling for us to test Native AOT. @@ -108,23 +104,23 @@ await RetryHelper.RetryAsync( SourceCode .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$TargetFramework$", TargetFrameworks.NetCurrent.Arguments) + .PatchCodeWithReplace("$TargetFramework$", TargetFrameworks.NetCurrent) .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) .PatchCodeWithReplace("$MSTestEngineVersion$", MSTestEngineVersion), addPublicFeeds: true); await DotnetCli.RunAsync( $"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, retryCount: 0); DotnetMuxerResult compilationResult = await DotnetCli.RunAsync( $"publish -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, timeoutInSeconds: 90, retryCount: 0); compilationResult.AssertOutputContains("Generating native code"); - var testHost = TestHost.LocateFrom(generator.TargetAssetPath, "NativeAotTests", TargetFrameworks.NetCurrent.Arguments, RID, Verb.publish); + var testHost = TestHost.LocateFrom(generator.TargetAssetPath, "NativeAotTests", TargetFrameworks.NetCurrent, RID, Verb.publish); TestHostResult result = await testHost.ExecuteAsync(); result.AssertExitCodeIs(0); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ParameterizedTestTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ParameterizedTestTests.cs index 74583168d5..dc22dbb698 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ParameterizedTestTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ParameterizedTestTests.cs @@ -7,45 +7,45 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class ParameterizedTestTests : AcceptanceTestBase +[TestClass] +public class ParameterizedTestTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; private const string DynamicDataAssetName = "DynamicData"; private const string DataSourceAssetName = "DataSource"; - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public ParameterizedTestTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SendingEmptyDataToDynamicDataTest_WithSettingConsiderEmptyDataSourceAsInconclusive_Passes(string currentTfm) => await RunTestsAsync(currentTfm, DynamicDataAssetName, true); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SendingEmptyDataToDataSourceTest_WithSettingConsiderEmptyDataSourceAsInconclusive_Passes(string currentTfm) => await RunTestsAsync(currentTfm, DataSourceAssetName, true); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SendingEmptyDataToDynamicDataTest_WithSettingConsiderEmptyDataSourceAsInconclusiveToFalse_Fails(string currentTfm) => await RunTestsAsync(currentTfm, DynamicDataAssetName, false); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SendingEmptyDataToDataSourceTest_WithSettingConsiderEmptyDataSourceAsInconclusiveToFalse_Fails(string currentTfm) => await RunTestsAsync(currentTfm, DataSourceAssetName, false); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SendingEmptyDataToDynamicDataTest_WithoutSettingConsiderEmptyDataSourceAsInconclusive_Fails(string currentTfm) => await RunTestsAsync(currentTfm, DynamicDataAssetName, null); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task SendingEmptyDataToDataSourceTest_WithoutSettingConsiderEmptyDataSourceAsInconclusive_Fails(string currentTfm) => await RunTestsAsync(currentTfm, DataSourceAssetName, null); private async Task RunTestsAsync(string currentTfm, string assetName, bool? isEmptyDataInconclusive) { - var testHost = TestHost.LocateFrom(_testAssetFixture.GetAssetPath(assetName), assetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.GetAssetPath(assetName), assetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync(SetupRunSettingsAndGetArgs(isEmptyDataInconclusive)); @@ -79,8 +79,7 @@ private async Task RunTestsAsync(string currentTfm, string assetName, bool? isEm } } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string DynamicDataTargetAssetPath => GetAssetPath(DynamicDataAssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Program.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Program.cs index f2d4e27817..8234276d1a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Program.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Program.cs @@ -2,11 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Diagnostics; +using System.Reflection; using Microsoft.Testing.Extensions; -using Microsoft.Testing.Internal.Framework.Configurations; -using MSTest.Acceptance.IntegrationTests; +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] // Opt-out telemetry Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1"); @@ -16,9 +17,7 @@ ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework( - new TestFrameworkConfiguration(Debugger.IsAttached ? 1 : Environment.ProcessorCount), - new SourceGeneratedTestNodesBuilder()); +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); #endif diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Properties/launchSettings.json b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Properties/launchSettings.json index f422322857..cdc273e704 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Properties/launchSettings.json +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "MSTest.Acceptance.IntegrationTests": { "commandName": "Project", - "commandLineArgs": "--treenode-filter /*/*/*/**" + "commandLineArgs": "" } } } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/PublishAotNonNativeTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/PublishAotNonNativeTests.cs index 750930798b..f26805a69a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/PublishAotNonNativeTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/PublishAotNonNativeTests.cs @@ -10,23 +10,21 @@ namespace MSTest.Acceptance.IntegrationTests; /// When PublishAOT=true is set on a project, it will set IsDynamicCodeSupported to false, but the code will still run as managed /// and VSTest is still able to find tests in the dll. /// -[TestGroup] -public sealed class PublishAotNonNativeTests : AcceptanceTestBase +[TestClass] +public sealed class PublishAotNonNativeTests : AcceptanceTestBase { private const string AssetName = "PublishAotNonNative"; - public PublishAotNonNativeTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - + [TestMethod] public async Task RunTests_ThatEnablePublishAOT_ButDontBuildToNative() { using TestAsset generator = await TestAsset.GenerateAssetAsync( - AssetName, - SourceCode - .PatchCodeWithReplace("$TargetFramework$", $"{TargetFrameworks.NetCurrent.Arguments}") - .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); + AssetName, + SourceCode + .PatchCodeWithReplace("$TargetFramework$", $"{TargetFrameworks.NetCurrent}") + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -c Debug {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -c Debug {generator.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); // In the real-world issue, access to path C:\Program Files\dotnet\ is denied, but we run this from a local .dotnet folder, where we have write access. // So instead of relying on the test run failing because of AccessDenied, we check the output, and see where TestResults were placed. @@ -80,6 +78,4 @@ public void TestMethod1() } } """; - - private readonly AcceptanceFixture _acceptanceFixture; } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunnerTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunnerTests.cs index 38255a5b64..70bb55ddc9 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunnerTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunnerTests.cs @@ -5,21 +5,17 @@ using Microsoft.Testing.Platform.Acceptance.IntegrationTests; using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using SL = Microsoft.Build.Logging.StructuredLogger; using SystemTask = System.Threading.Tasks.Task; namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class RunnerTests : AcceptanceTestBase +[TestClass] +public class RunnerTests : AcceptanceTestBase { private const string AssetName = "MSTestProject"; - private readonly AcceptanceFixture _acceptanceFixture; - public RunnerTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async SystemTask EnableMSTestRunner_True_Will_Run_Standalone(string tfm, BuildConfiguration buildConfiguration, Verb verb) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -34,22 +30,22 @@ public async SystemTask EnableMSTestRunner_True_Will_Run_Standalone(string tfm, string binlogFile = Path.Combine(generator.TargetAssetPath, "msbuild.binlog"); DotnetMuxerResult compilationResult = await DotnetCli.RunAsync( $"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + AcceptanceFixture.NuGetGlobalPackagesFolder.Path); compilationResult = await DotnetCli.RunAsync( $"{verb} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -bl:{binlogFile} -r {RID}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + AcceptanceFixture.NuGetGlobalPackagesFolder.Path); - SL.Build binLog = Serialization.Read(binlogFile); - Assert.IsNotEmpty(binLog.FindChildrenRecursive() - .Where(x => x.Title.Contains("ProjectCapability")) - .Where(x => x.Children.Any(c => ((Item)c).Name == "TestingPlatformServer"))); + Build binLog = Serialization.Read(binlogFile); + Assert.AreNotEqual(0, binLog.FindChildrenRecursive() + .Count(x => x.Title.Contains("ProjectCapability") && x.Children.Any(c => ((Item)c).Name == "TestingPlatformServer"))); var testHost = TestHost.LocateFrom(generator.TargetAssetPath, AssetName, tfm, buildConfiguration: buildConfiguration, verb: verb); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async SystemTask EnableMSTestRunner_True_WithCustomEntryPoint_Will_Run_Standalone(string tfm, BuildConfiguration buildConfiguration, Verb verb) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -75,16 +71,17 @@ public async SystemTask EnableMSTestRunner_True_WithCustomEntryPoint_Will_Run_St preview """)); string binlogFile = Path.Combine(generator.TargetAssetPath, "msbuild.binlog"); - await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); await DotnetCli.RunAsync( $"{verb} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -bl:{binlogFile} -r {RID}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + AcceptanceFixture.NuGetGlobalPackagesFolder.Path); var testHost = TestHost.LocateFrom(generator.TargetAssetPath, AssetName, tfm, buildConfiguration: buildConfiguration, verb: verb); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async SystemTask EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_From_Tpv2_SDK(string tfm, BuildConfiguration buildConfiguration, Verb verb) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -97,17 +94,17 @@ public async SystemTask EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoi .PatchCodeWithReplace("$OutputType$", "Exe") .PatchCodeWithReplace("$Extra$", string.Empty)); string binlogFile = Path.Combine(generator.TargetAssetPath, "msbuild.binlog"); - await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); try { - await DotnetCli.RunAsync($"{verb} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -bl:{binlogFile} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"{verb} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -bl:{binlogFile} -r {RID}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); var testHost = TestHost.LocateFrom(generator.TargetAssetPath, AssetName, tfm, buildConfiguration: buildConfiguration, verb: verb); TestHostResult testHostResult = await testHost.ExecuteAsync(); Assert.AreEqual(string.Empty, testHostResult.StandardOutput); } catch (Exception ex) { - if (TargetFrameworks.NetFramework.Any(x => x.Arguments == tfm)) + if (TargetFrameworks.NetFramework.Any(x => x == tfm)) { Assert.IsTrue(ex.Message.Contains("Program does not contain a static 'Main' method suitable for an entry point"), ex.Message); @@ -117,7 +114,8 @@ public async SystemTask EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoi } } - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async SystemTask EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string tfm, BuildConfiguration buildConfiguration, Verb verb) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -131,12 +129,11 @@ public async SystemTask EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer .PatchCodeWithReplace("$Extra$", string.Empty)); string binlogFile = Path.Combine(generator.TargetAssetPath, "msbuild.binlog"); - await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); - await DotnetCli.RunAsync($"{verb} -bl:{binlogFile} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -r {RID} ", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"{verb} -bl:{binlogFile} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -r {RID} ", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); - SL.Build binLog = Serialization.Read(binlogFile); - Assert.IsEmpty(binLog.FindChildrenRecursive() - .Where(x => x.Title.Contains("ProjectCapability")) - .Where(x => x.Children.Any(c => ((Item)c).Name == "TestingPlatformServer"))); + Build binLog = Serialization.Read(binlogFile); + Assert.IsFalse(binLog.FindChildrenRecursive() + .Any(x => x.Title.Contains("ProjectCapability") && x.Children.Any(c => ((Item)c).Name == "TestingPlatformServer"))); } } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunsettingsTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunsettingsTests.cs index d7d87424a3..9bdbb88338 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunsettingsTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RunsettingsTests.cs @@ -10,50 +10,40 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class RunSettingsTests : AcceptanceTestBase +[TestClass] +public sealed class RunSettingsTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public RunSettingsTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - internal static IEnumerable> TfmList() - { - yield return TargetFrameworks.NetCurrent; - yield return TargetFrameworks.NetFramework.First(); - } - - internal static IEnumerable> LocalizationTestCases() + internal static IEnumerable<(string? TestingPlatformUILanguage, string? DotnetCLILanguage, string? VSLang, string ExpectedLocale)> LocalizationTestCases() { // Show that TestingPlatformUILanguage is respected. - yield return new TestArgumentsEntry<(string?, string?, string?, string)>(("fr-FR", null, null, "fr-FR"), "TestingPlatformUILanguage: fr-FR, expected: fr-FR"); + yield return new("fr-FR", null, null, "fr-FR"); // Show that TestingPlatformUILanguage takes precedence over DotnetCLILanguage. - yield return new TestArgumentsEntry<(string?, string?, string?, string)>(("fr-FR", "it-IT", null, "fr-FR"), "TestingPlatformUILanguage: fr-FR, CLI: it-IT, expected: fr-FR"); + yield return new("fr-FR", "it-IT", null, "fr-FR"); // Show that DotnetCLILanguage is respected. - yield return new TestArgumentsEntry<(string?, string?, string?, string)>((null, "it-IT", null, "it-IT"), "CLI: it-IT, expected: it-IT"); + yield return new(null, "it-IT", null, "it-IT"); // Show that DotnetCLILanguage takes precedence over VSLang. - yield return new TestArgumentsEntry<(string?, string?, string?, string)>((null, "it-IT", "fr-FR", "it-IT"), "CLI: it-IT, VSLang: fr-FR, expected: it-IT"); + yield return new(null, "it-IT", "fr-FR", "it-IT"); // Show that VSLang is respected. - yield return new TestArgumentsEntry<(string?, string?, string?, string)>((null, null, "it-IT", "it-IT"), "VSLang: it-IT, expected: it-IT"); + yield return new(null, null, "it-IT", "it-IT"); // Show that TestingPlatformUILanguage takes precedence over everything. - yield return new TestArgumentsEntry<(string?, string?, string?, string)>(("fr-FR", "it-IT", "it-IT", "fr-FR"), "TestingPlatformUILanguage: fr-FR, CLI: it-IT, VSLang: it-IT, expected: fr-FR"); + yield return new("fr-FR", "it-IT", "it-IT", "fr-FR"); } - [ArgumentsProvider(nameof(TfmList))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task UnsupportedRunSettingsEntriesAreFlagged(string tfm) { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && tfm == TargetFrameworks.NetFramework.First().Arguments) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && tfm == TargetFrameworks.NetFramework.First()) { return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings"); // Assert @@ -71,21 +61,22 @@ public async Task UnsupportedRunSettingsEntriesAreFlagged(string tfm) testHostResult.AssertOutputContains("Runsettings attribute 'TreatNoTestsAsError' is not supported by Microsoft.Testing.Platform and will be ignored"); } - [ArgumentsProvider(nameof(LocalizationTestCases))] - public async Task UnsupportedRunSettingsEntriesAreFlagged_Localization((string? TestingPlatformUILanguage, string? DotnetCLILanguage, string? VSLang, string? ExpectedLocale) testArgument) + [TestMethod] + [DynamicData(nameof(LocalizationTestCases), DynamicDataSourceType.Method)] + public async Task UnsupportedRunSettingsEntriesAreFlagged_Localization(string? testingPlatformUILanguage, string? dotnetCLILanguage, string? vsLang, string? expectedLocale) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings", environmentVariables: new() { - ["TESTINGPLATFORM_UI_LANGUAGE"] = testArgument.TestingPlatformUILanguage, - ["DOTNET_CLI_UI_LANGUAGE"] = testArgument.DotnetCLILanguage, - ["VSLANG"] = testArgument.VSLang is null ? null : new CultureInfo(testArgument.VSLang).LCID.ToString(CultureInfo.CurrentCulture), + ["TESTINGPLATFORM_UI_LANGUAGE"] = testingPlatformUILanguage, + ["DOTNET_CLI_UI_LANGUAGE"] = dotnetCLILanguage, + ["VSLANG"] = vsLang is null ? null : new CultureInfo(vsLang).LCID.ToString(CultureInfo.CurrentCulture), }); // Assert testHostResult.AssertExitCodeIs(0); - switch (testArgument.ExpectedLocale) + switch (expectedLocale) { case "fr-FR": testHostResult.AssertOutputContains("Les loggers Runsettings ne sont pas pris en charge par Microsoft.Testing.Platform et seront ignorés"); @@ -100,8 +91,7 @@ public async Task UnsupportedRunSettingsEntriesAreFlagged_Localization((string? } } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestRunSettings"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestClassTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestClassTests.cs index 3c85fd28f2..02f884fb7a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestClassTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestClassTests.cs @@ -8,20 +8,15 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class STATestClassTests : AcceptanceTestBase +[TestClass] +public sealed class STATestClassTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; private const string AssetName = "STATestClass"; private const string TimeoutAssetName = "TimeoutSTATestClass"; private const string CooperativeTimeoutAssetName = "CooperativeTimeoutSTATestClass"; - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public STATestClassTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestClass_OnWindows_OnLifeCycleTestClass_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -29,7 +24,7 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClass_FixturesAndMethods return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClass"); @@ -46,7 +41,8 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClass_FixturesAndMethods testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -54,7 +50,7 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClassWithLastTestSkipped"); @@ -71,7 +67,8 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestClass_OnWindows_OnLifeCycleTestClass_WithTimeout_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -79,7 +76,7 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClass_WithTimeout_Fixtur return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetTimeoutAssetPath, TimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetTimeoutAssetPath, TimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClass"); @@ -96,7 +93,8 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClass_WithTimeout_Fixtur testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped_WithTimeout_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -104,7 +102,7 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetTimeoutAssetPath, TimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetTimeoutAssetPath, TimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClassWithLastTestSkipped"); @@ -121,7 +119,8 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestClass_OnWindows_OnLifeCycleTestClass_WithCooperativeTimeout_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -129,7 +128,7 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClass_WithCooperativeTim return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetCooperativeTimeoutAssetPath, CooperativeTimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetCooperativeTimeoutAssetPath, CooperativeTimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClass"); @@ -146,7 +145,8 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClass_WithCooperativeTim testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped_WithCooperativeTimeout_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -154,7 +154,7 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetCooperativeTimeoutAssetPath, CooperativeTimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetCooperativeTimeoutAssetPath, CooperativeTimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClassWithLastTestSkipped"); @@ -171,7 +171,8 @@ public async Task STATestClass_OnWindows_OnLifeCycleTestClassWithLastTestSkipped testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DerivedSTATestClass_OnWindows_OnTestClassWithClassCleanupEndOfAssembly_ClassCleanupIsMTA(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -179,7 +180,7 @@ public async Task DerivedSTATestClass_OnWindows_OnTestClassWithClassCleanupEndOf return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithClassCleanupEndOfAssembly"); @@ -196,8 +197,7 @@ public async Task DerivedSTATestClass_OnWindows_OnTestClassWithClassCleanupEndOf testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string TargetAssetPath => GetAssetPath(AssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestMethodTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestMethodTests.cs index b1b8b523e1..031b6858c3 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestMethodTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/STATestMethodTests.cs @@ -8,20 +8,15 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class STATestMethodTests : AcceptanceTestBase +[TestClass] +public sealed class STATestMethodTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; private const string AssetName = "STATestMethodProject"; private const string TimeoutAssetName = "TimeoutSTATestMethodProject"; private const string CooperativeTimeoutAssetName = "CooperativeTimeoutSTATestMethodProject"; - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public STATestMethodTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -29,7 +24,7 @@ public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_FixturesAndMethod return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClass"); @@ -46,7 +41,8 @@ public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_FixturesAndMethod testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DerivedSTATestMethod_OnWindows_OnTestClassWithClassCleanupEndOfAssembly(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -54,7 +50,7 @@ public async Task DerivedSTATestMethod_OnWindows_OnTestClassWithClassCleanupEndO return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithClassCleanupEndOfAssembly"); @@ -71,7 +67,8 @@ public async Task DerivedSTATestMethod_OnWindows_OnTestClassWithClassCleanupEndO testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_MethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -79,7 +76,7 @@ public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_MethodsAr return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithMultipleTests"); @@ -99,7 +96,8 @@ public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_MethodsAr testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_WithTimeout_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -107,7 +105,7 @@ public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_WithTimeout_Fixtu return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TimeoutTargetAssetPath, TimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TimeoutTargetAssetPath, TimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClass"); @@ -124,7 +122,8 @@ public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_WithTimeout_Fixtu testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DerivedSTATestMethod_OnWindows_WithTimeout_OnTestClassWithClassCleanupEndOfAssembly(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -132,7 +131,7 @@ public async Task DerivedSTATestMethod_OnWindows_WithTimeout_OnTestClassWithClas return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TimeoutTargetAssetPath, TimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TimeoutTargetAssetPath, TimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithClassCleanupEndOfAssembly"); @@ -149,7 +148,8 @@ public async Task DerivedSTATestMethod_OnWindows_WithTimeout_OnTestClassWithClas testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_WithTimeout_MethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -157,7 +157,7 @@ public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_WithTimeo return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.TimeoutTargetAssetPath, TimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TimeoutTargetAssetPath, TimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithMultipleTests"); @@ -177,7 +177,8 @@ public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_WithTimeo testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_WithCooperativeTimeout_FixturesAndMethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -185,7 +186,7 @@ public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_WithCooperativeTi return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutTargetAssetPath, CooperativeTimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutTargetAssetPath, CooperativeTimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=LifeCycleTestClass"); @@ -202,7 +203,8 @@ public async Task STATestMethod_OnWindows_OnLifeCycleTestClass_WithCooperativeTi testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DerivedSTATestMethod_OnWindows_WithCooperativeTimeout_OnTestClassWithClassCleanupEndOfAssembly(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -210,7 +212,7 @@ public async Task DerivedSTATestMethod_OnWindows_WithCooperativeTimeout_OnTestCl return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutTargetAssetPath, CooperativeTimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutTargetAssetPath, CooperativeTimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithClassCleanupEndOfAssembly"); @@ -227,7 +229,8 @@ public async Task DerivedSTATestMethod_OnWindows_WithCooperativeTimeout_OnTestCl testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_WithCooperativeTimeout_MethodsAreOnExpectedApartmentState(string currentTfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -235,7 +238,7 @@ public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_WithCoope return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.CooperativeTimeoutTargetAssetPath, CooperativeTimeoutAssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.CooperativeTimeoutTargetAssetPath, CooperativeTimeoutAssetName, currentTfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath} --filter className=TestClassWithMultipleTests"); @@ -255,8 +258,7 @@ public async Task STATestMethod_OnWindows_OnTestClassWithMultipleTests_WithCoope testHostResult.AssertOutputContains("LifeCycleTestClass.AssemblyCleanup"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string TargetAssetPath => GetAssetPath(AssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs index 22c7931d86..540b214800 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs @@ -11,8 +11,8 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class SdkTests : AcceptanceTestBase +[TestClass] +public sealed class SdkTests : AcceptanceTestBase { private const string AssetName = "MSTestSdk"; @@ -51,17 +51,8 @@ public void TestMethod1() } """; - private readonly AcceptanceFixture _acceptanceFixture; - private readonly TestAssetFixture _testAssetFixture; - - public SdkTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture, TestAssetFixture testAssetFixture) - : base(testExecutionContext) - { - _acceptanceFixture = acceptanceFixture; - _testAssetFixture = testAssetFixture; - } - - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task RunTests_With_VSTest(string multiTfm, BuildConfiguration buildConfiguration) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -71,23 +62,24 @@ public async Task RunTests_With_VSTest(string multiTfm, BuildConfiguration build .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", "true")); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); - compilationResult.AssertOutputRegEx(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net9\.0\)"); + compilationResult.AssertOutputMatchesRegex(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net9\.0\)"); #if !SKIP_INTERMEDIATE_TARGET_FRAMEWORKS - compilationResult.AssertOutputRegEx(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net8\.0\)"); - compilationResult.AssertOutputRegEx(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net7\.0\)"); - compilationResult.AssertOutputRegEx(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net6\.0\)"); + compilationResult.AssertOutputMatchesRegex(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net8\.0\)"); + compilationResult.AssertOutputMatchesRegex(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net7\.0\)"); + compilationResult.AssertOutputMatchesRegex(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net6\.0\)"); #endif if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - compilationResult.AssertOutputRegEx(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net462\)"); + compilationResult.AssertOutputMatchesRegex(@"Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: .* [m]?s - MSTestSdk.dll \(net462\)"); } } - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task RunTests_With_MSTestRunner_DotnetTest(string multiTfm, BuildConfiguration buildConfiguration) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -97,23 +89,24 @@ public async Task RunTests_With_MSTestRunner_DotnetTest(string multiTfm, BuildCo .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", string.Empty)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); - compilationResult.AssertOutputRegEx(@"Tests succeeded: .* \[net9\.0|x64\]"); + compilationResult.AssertOutputMatchesRegex(@"Tests succeeded: .* \[net9\.0|x64\]"); #if !SKIP_INTERMEDIATE_TARGET_FRAMEWORKS - compilationResult.AssertOutputRegEx(@"Tests succeeded: .* \[net8\.0|x64\]"); - compilationResult.AssertOutputRegEx(@"Tests succeeded: .* \[net7\.0|x64\]"); - compilationResult.AssertOutputRegEx(@"Tests succeeded: .* \[net6\.0|x64\]"); + compilationResult.AssertOutputMatchesRegex(@"Tests succeeded: .* \[net8\.0|x64\]"); + compilationResult.AssertOutputMatchesRegex(@"Tests succeeded: .* \[net7\.0|x64\]"); + compilationResult.AssertOutputMatchesRegex(@"Tests succeeded: .* \[net6\.0|x64\]"); #endif if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - compilationResult.AssertOutputRegEx(@"Tests succeeded: .* \[net462|x64\]"); + compilationResult.AssertOutputMatchesRegex(@"Tests succeeded: .* \[net462|x64\]"); } } - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task RunTests_With_MSTestRunner_Standalone(string multiTfm, BuildConfiguration buildConfiguration) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -123,7 +116,7 @@ public async Task RunTests_With_MSTestRunner_Standalone(string multiTfm, BuildCo .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", string.Empty)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); foreach (string tfm in multiTfm.Split(";")) { @@ -133,7 +126,8 @@ public async Task RunTests_With_MSTestRunner_Standalone(string multiTfm, BuildCo } } - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task RunTests_With_CentralPackageManagement_Standalone(string multiTfm, BuildConfiguration buildConfiguration) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -143,7 +137,7 @@ public async Task RunTests_With_CentralPackageManagement_Standalone(string multi .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", string.Empty)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); foreach (string tfm in multiTfm.Split(";")) { @@ -153,48 +147,39 @@ public async Task RunTests_With_CentralPackageManagement_Standalone(string multi } } - public static IEnumerable> RunTests_With_MSTestRunner_Standalone_Plus_Extensions_Data() + public static IEnumerable<(string MultiTfm, BuildConfiguration BuildConfiguration, string MSBuildExtensionEnableFragment, string EnableCommandLineArg, string InvalidCommandLineArg)> RunTests_With_MSTestRunner_Standalone_Plus_Extensions_Data() { - foreach (TestArgumentsEntry<(string MultiTfm, BuildConfiguration BuildConfiguration)> buildConfig in GetBuildMatrixMultiTfmFoldedBuildConfiguration()) + foreach ((string MultiTfm, BuildConfiguration BuildConfiguration) buildConfig in GetBuildMatrixMultiTfmFoldedBuildConfiguration()) { - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string, string)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, "true", "--coverage", - "--crashdump"), - $"multitfm,{buildConfig.Arguments.BuildConfiguration},CodeCoverage"); + "--crashdump"); - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string, string)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, "true", "--retry-failed-tests 3", - "--crashdump"), - $"multitfm,{buildConfig.Arguments.BuildConfiguration},Retry"); + "--crashdump"); - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string, string)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, "true", "--report-trx", - "--crashdump"), - $"multitfm,{buildConfig.Arguments.BuildConfiguration},TrxReport"); + "--crashdump"); - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string, string)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, "true", "--crashdump", - "--hangdump"), - $"multitfm,{buildConfig.Arguments.BuildConfiguration},CrashDump"); + "--hangdump"); - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string, string)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, "true", "--hangdump", - "--crashdump"), - $"multitfm,{buildConfig.Arguments.BuildConfiguration},HangDump"); + "--crashdump"); } } - [ArgumentsProvider(nameof(RunTests_With_MSTestRunner_Standalone_Plus_Extensions_Data))] + [TestMethod] + [DynamicData(nameof(RunTests_With_MSTestRunner_Standalone_Plus_Extensions_Data), DynamicDataSourceType.Method)] public async Task RunTests_With_MSTestRunner_Standalone_Selectively_Enabled_Extensions(string multiTfm, BuildConfiguration buildConfiguration, string msbuildExtensionEnableFragment, string enableCommandLineArg, @@ -207,7 +192,7 @@ public async Task RunTests_With_MSTestRunner_Standalone_Selectively_Enabled_Exte .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", msbuildExtensionEnableFragment)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); foreach (string tfm in multiTfm.Split(";")) { @@ -220,7 +205,8 @@ public async Task RunTests_With_MSTestRunner_Standalone_Selectively_Enabled_Exte } } - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task RunTests_With_MSTestRunner_Standalone_EnableAll_Extensions(string multiTfm, BuildConfiguration buildConfiguration) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -230,7 +216,7 @@ public async Task RunTests_With_MSTestRunner_Standalone_EnableAll_Extensions(str .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", "AllMicrosoft")); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); foreach (string tfm in multiTfm.Split(";")) { @@ -240,21 +226,17 @@ public async Task RunTests_With_MSTestRunner_Standalone_EnableAll_Extensions(str } } - public static IEnumerable> RunTests_With_MSTestRunner_Standalone_Default_Extensions_Data() + public static IEnumerable<(string MultiTfm, BuildConfiguration BuildConfiguration, bool EnableDefaultExtensions)> RunTests_With_MSTestRunner_Standalone_Default_Extensions_Data() { - foreach (TestArgumentsEntry<(string MultiTfm, BuildConfiguration BuildConfiguration)> buildConfig in GetBuildMatrixMultiTfmFoldedBuildConfiguration()) + foreach ((string MultiTfm, BuildConfiguration BuildConfiguration) buildConfig in GetBuildMatrixMultiTfmFoldedBuildConfiguration()) { - yield return new TestArgumentsEntry<(string, BuildConfiguration, bool)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, true), - $"enabled,{buildConfig.Arguments.BuildConfiguration},CodeCoverage"); - - yield return new TestArgumentsEntry<(string, BuildConfiguration, bool)>( - (buildConfig.Arguments.MultiTfm, buildConfig.Arguments.BuildConfiguration, false), - $"disabled,{buildConfig.Arguments.BuildConfiguration},CodeCoverage"); + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, true); + yield return new(buildConfig.MultiTfm, buildConfig.BuildConfiguration, false); } } - [ArgumentsProvider(nameof(RunTests_With_MSTestRunner_Standalone_Default_Extensions_Data))] + [TestMethod] + [DynamicData(nameof(RunTests_With_MSTestRunner_Standalone_Default_Extensions_Data), DynamicDataSourceType.Method)] public async Task RunTests_With_MSTestRunner_Standalone_Enable_Default_Extensions(string multiTfm, BuildConfiguration buildConfiguration, bool enableDefaultExtensions) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -264,7 +246,7 @@ public async Task RunTests_With_MSTestRunner_Standalone_Enable_Default_Extension .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", enableDefaultExtensions ? string.Empty : "None")); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); foreach (string tfm in multiTfm.Split(";")) { @@ -281,7 +263,8 @@ public async Task RunTests_With_MSTestRunner_Standalone_Enable_Default_Extension } } - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))] + [TestMethod] + [DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] public async Task Invalid_TestingProfile_Name_Should_Fail(string multiTfm, BuildConfiguration buildConfiguration) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -291,11 +274,12 @@ public async Task Invalid_TestingProfile_Name_Should_Fail(string multiTfm, Build .PatchCodeWithReplace("$TargetFramework$", multiTfm) .PatchCodeWithReplace("$ExtraProperties$", "WrongName")); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); Assert.AreEqual(1, compilationResult.ExitCode); compilationResult.AssertOutputContains("Invalid value for property TestingExtensionsProfile. Valid values are 'Default', 'AllMicrosoft' and 'None'."); } + [TestMethod] public async Task NativeAot_Smoke_Test_Windows() // The native AOT publication is pretty flaky and is often failing on CI with "fatal error LNK1136: invalid or corrupt file", // or sometimes doesn't fail but the native code generation is not done. @@ -323,12 +307,12 @@ public async Task NativeAot_Smoke_Test_Windows() DotnetMuxerResult compilationResult = await DotnetCli.RunAsync( $"publish -r {RID} -f net9.0 {testAsset.TargetAssetPath}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, // We prefer to use the outer retry mechanism as we need some extra checks retryCount: 0, timeoutInSeconds: 180); compilationResult.AssertOutputContains("Generating native code"); - compilationResult.AssertOutputNotContains("warning"); + compilationResult.AssertOutputDoesNotContain("warning"); var testHost = TestHost.LocateFrom(testAsset.TargetAssetPath, AssetName, "net9.0", verb: Verb.publish); TestHostResult testHostResult = await testHost.ExecuteAsync(); @@ -337,10 +321,11 @@ public async Task NativeAot_Smoke_Test_Windows() testHostResult.AssertOutputContainsSummary(0, 1, 0); }, times: 15, every: TimeSpan.FromSeconds(5)); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task EnablePlaywrightProperty_WhenUsingRunner_AllowsToRunPlaywrightTests(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.PlaywrightProjectPath, TestAssetFixture.PlaywrightProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.PlaywrightProjectPath, TestAssetFixture.PlaywrightProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); // Depending on the machine, the test might fail due to the browser not being installed. @@ -361,16 +346,17 @@ public async Task EnablePlaywrightProperty_WhenUsingRunner_AllowsToRunPlaywright } } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task EnablePlaywrightProperty_WhenUsingVSTest_AllowsToRunPlaywrightTests(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.PlaywrightProjectPath, TestAssetFixture.PlaywrightProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.PlaywrightProjectPath, TestAssetFixture.PlaywrightProjectName, tfm); string exeOrDllName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? testHost.FullName : testHost.FullName + ".dll"; DotnetMuxerResult dotnetTestResult = await DotnetCli.RunAsync( $"test {exeOrDllName}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false, warnAsError: false, suppressPreviewDotNetMessage: false); @@ -396,22 +382,24 @@ public async Task EnablePlaywrightProperty_WhenUsingVSTest_AllowsToRunPlaywright } } + [TestMethod] public async Task EnableAspireProperty_WhenUsingRunner_AllowsToRunAspireTests() { - var testHost = TestHost.LocateFrom(_testAssetFixture.AspireProjectPath, TestAssetFixture.AspireProjectName, TargetFrameworks.NetCurrent.UidFragment); + var testHost = TestHost.LocateFrom(AssetFixture.AspireProjectPath, TestAssetFixture.AspireProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertOutputContainsSummary(0, 1, 0); } + [TestMethod] public async Task EnableAspireProperty_WhenUsingVSTest_AllowsToRunAspireTests() { - var testHost = TestHost.LocateFrom(_testAssetFixture.AspireProjectPath, TestAssetFixture.AspireProjectName, TargetFrameworks.NetCurrent.UidFragment); + var testHost = TestHost.LocateFrom(AssetFixture.AspireProjectPath, TestAssetFixture.AspireProjectName, TargetFrameworks.NetCurrent); string exeOrDllName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? testHost.FullName : testHost.FullName + ".dll"; DotnetMuxerResult dotnetTestResult = await DotnetCli.RunAsync( $"test {exeOrDllName}", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, warnAsError: false, suppressPreviewDotNetMessage: false); Assert.AreEqual(0, dotnetTestResult.ExitCode); @@ -420,17 +408,18 @@ public async Task EnableAspireProperty_WhenUsingVSTest_AllowsToRunAspireTests() dotnetTestResult.AssertOutputContains("Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1"); } + [TestMethod] public async Task SettingIsTestApplicationToFalseReducesAddedExtensionsAndMakesProjectNotExecutable() { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( AssetName, SingleTestSourceCode .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) - .PatchCodeWithReplace("$TargetFramework$", TargetFrameworks.NetCurrent.UidFragment) + .PatchCodeWithReplace("$TargetFramework$", TargetFrameworks.NetCurrent) .PatchCodeWithReplace("$ExtraProperties$", "false")); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test {testAsset.TargetAssetPath} -bl:{binlogFile}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"test {testAsset.TargetAssetPath} -bl:{binlogFile}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.AreEqual(0, compilationResult.ExitCode); @@ -450,9 +439,7 @@ public async Task SettingIsTestApplicationToFalseReducesAddedExtensionsAndMakesP Assert.IsFalse(binLog.FindChildrenRecursive(p => p.Name == "OutputType").Any(p => p.Value == "Exe")); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture _acceptanceFixture) - : TestAssetFixtureBase(_acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string AspireProjectName = "AspireProject"; public const string PlaywrightProjectName = "PlaywrightProject"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerMode/ServerModeTestsBase.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerMode/ServerModeTestsBase.cs index d31bf62902..00f2a47feb 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerMode/ServerModeTestsBase.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerMode/ServerModeTestsBase.cs @@ -13,7 +13,8 @@ namespace MSTest.Acceptance.IntegrationTests.Messages.V100; -public partial /* for codegen regx */ class ServerModeTestsBase : AcceptanceTestBase +public partial /* for codegen regx */ class ServerModeTestsBase : AcceptanceTestBase + where TFixture : TestAssetFixtureBase, new() { private static readonly string Root = RootFinder.Find(); private static readonly Dictionary DefaultEnvironmentVariables = new() @@ -24,11 +25,6 @@ namespace MSTest.Acceptance.IntegrationTests.Messages.V100; { "DOTNET_MULTILEVEL_LOOKUP", "0" }, }; - protected ServerModeTestsBase(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - protected async Task StartAsServerAndConnectToTheClientAsync(TestHost testHost) { var environmentVariables = new Dictionary(DefaultEnvironmentVariables); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerModeTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerModeTests.cs index 989d5feae1..3449eb1a14 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerModeTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ServerModeTests.cs @@ -8,18 +8,14 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class ServerModeTests : ServerModeTestsBase +[TestClass] +public sealed class ServerModeTests : ServerModeTestsBase { - private readonly TestAssetFixture _fixture; - - public ServerModeTests(ITestExecutionContext testExecutionContext, TestAssetFixture fixture) - : base(testExecutionContext) => _fixture = fixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DiscoverAndRun(string tfm) { - using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(TestHost.LocateFrom(_fixture.ProjectPath, "MSTestProject", tfm, buildConfiguration: BuildConfiguration.Release)); + using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(TestHost.LocateFrom(AssetFixture.ProjectPath, "MSTestProject", tfm, buildConfiguration: BuildConfiguration.Release)); LogsCollector logs = new(); jsonClient.RegisterLogListener(logs); TelemetryCollector telemetry = new(); @@ -40,17 +36,18 @@ public async Task DiscoverAndRun(string tfm) await Task.WhenAll(discoveryListener.WaitCompletion(), runListener.WaitCompletion()); Assert.AreEqual(1, discoveryCollector.TestNodeUpdates.Count(x => x.Node.NodeType == "action"), $"Wrong number of discovery"); Assert.AreEqual(2, runCollector.TestNodeUpdates.Count, $"Wrong number of updates"); - Assert.IsFalse(logs.Count == 0, $"Logs are empty"); + Assert.AreNotEqual(0, logs.Count, $"Logs are empty"); Assert.IsFalse(telemetry.IsEmpty, $"telemetry is empty"); await jsonClient.Exit(); Assert.AreEqual(0, await jsonClient.WaitServerProcessExit()); Assert.AreEqual(0, jsonClient.ExitCode); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task WhenClientDies_Server_ShouldClose_Gracefully(string tfm) { - using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(TestHost.LocateFrom(_fixture.ProjectPath, "MSTestProject", tfm, buildConfiguration: BuildConfiguration.Release)); + using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(TestHost.LocateFrom(AssetFixture.ProjectPath, "MSTestProject", tfm, buildConfiguration: BuildConfiguration.Release)); LogsCollector logs = new(); jsonClient.RegisterLogListener(logs); TelemetryCollector telemetry = new(); @@ -70,8 +67,7 @@ public async Task WhenClientDies_Server_ShouldClose_Gracefully(string tfm) Assert.AreEqual(3, exitCode); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "MSTestProject"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestContextTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestContextTests.cs index 152c28dc96..e387366476 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestContextTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestContextTests.cs @@ -6,17 +6,13 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class TestContextTests : AcceptanceTestBase +[TestClass] +public sealed class TestContextTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public TestContextTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task TestContextsAreCorrectlySet() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter ClassName~TestContextCtor"); // Assert @@ -24,9 +20,10 @@ public async Task TestContextsAreCorrectlySet() testHostResult.AssertOutputContainsSummary(failed: 0, passed: 5, skipped: 0); } + [TestMethod] public async Task TestContext_TestData_PropertyContainsExpectedValue() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter ClassName~TestContextData"); // Assert @@ -34,9 +31,10 @@ public async Task TestContext_TestData_PropertyContainsExpectedValue() testHostResult.AssertOutputContainsSummary(failed: 0, passed: 3, skipped: 0); } + [TestMethod] public async Task TestContext_TestException_PropertyContainsExpectedValue() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter ClassName~TestContextException"); // Assert @@ -46,9 +44,10 @@ public async Task TestContext_TestException_PropertyContainsExpectedValue() testHostResult.AssertOutputContains("Test method TestContextExceptionFailingInTestMethod.TestFailingInTestMethod threw exception:"); } + [TestMethod] public async Task TestContext_TestDisplayName_PropertyContainsExpectedValue() { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter ClassName~TestContextDisplayName"); // Assert @@ -56,8 +55,7 @@ public async Task TestContext_TestDisplayName_PropertyContainsExpectedValue() testHostResult.AssertOutputContainsSummary(failed: 0, passed: 4, skipped: 0); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestTestContext"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestDiscoveryTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestDiscoveryTests.cs index 8e0c7e53d0..bec1c9dd3a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestDiscoveryTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestDiscoveryTests.cs @@ -7,21 +7,16 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class TestDiscoveryTests : AcceptanceTestBase +[TestClass] +public class TestDiscoveryTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; private const string AssetName = "TestDiscovery"; - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public TestDiscoveryTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DiscoverTests_FindsAllTests(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests"); @@ -30,10 +25,11 @@ public async Task DiscoverTests_FindsAllTests(string currentTfm) testHostResult.AssertOutputContains("Test2"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DiscoverTests_WithFilter_FindsOnlyFilteredOnes(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests --filter Name=Test1"); @@ -42,8 +38,7 @@ public async Task DiscoverTests_WithFilter_FindsOnlyFilteredOnes(string currentT testHostResult.AssertOutputDoesNotContain("Test2"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string TargetAssetPath => GetAssetPath(AssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestFilterTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestFilterTests.cs index 03ee39c31a..aac2557286 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestFilterTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestFilterTests.cs @@ -7,21 +7,16 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class TestFilterTests : AcceptanceTestBase +[TestClass] +public class TestFilterTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; private const string AssetName = "TestFilter"; - // There's a bug in TAFX where we need to use it at least one time somewhere to use it inside the fixture self (AcceptanceFixture). - public TestFilterTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture, - AcceptanceFixture globalFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task RunWithFilter_UsingTestProperty_FilteredTests(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter tree=one"); @@ -29,10 +24,11 @@ public async Task RunWithFilter_UsingTestProperty_FilteredTests(string currentTf testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task DiscoverTestsWithFilter_UsingTestProperty_FilteredTests(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter tree=one --list-tests"); @@ -43,10 +39,11 @@ public async Task DiscoverTestsWithFilter_UsingTestProperty_FilteredTests(string """); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task UsingTestPropertyForOwnerAndPriorityAndTestCategory_TestsFailed(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter tree!~one"); @@ -60,10 +57,11 @@ failed TestCategoryTest (0ms) """); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task RunWithFilter_UsingTestPropertyForOwner_FilteredButTestsFailed(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter owner=testOwner"); @@ -73,10 +71,11 @@ failed OwnerTest (0ms) """); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task RunWithFilter_UsingTestPropertyForPriorityAndTestCategory_NotFiltered(string currentTfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--filter TestCategory=category|Priority=1"); @@ -84,8 +83,7 @@ public async Task RunWithFilter_UsingTestPropertyForPriorityAndTestCategory_NotF testHostResult.AssertExitCodeIs(8); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public string TargetAssetPath => GetAssetPath(AssetName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestRunParametersTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestRunParametersTests.cs index 723ded5cd7..e3c188cd43 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestRunParametersTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TestRunParametersTests.cs @@ -6,18 +6,14 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class TestRunParametersTests : AcceptanceTestBase +[TestClass] +public sealed class TestRunParametersTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public TestRunParametersTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestRunParameters_WhenProvidingMultipleArgumentsToTheOption(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings --test-parameter MyParameter2=MyValue2 MyParameter3=MyValue3"); // Assert @@ -25,10 +21,11 @@ public async Task TestRunParameters_WhenProvidingMultipleArgumentsToTheOption(st testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestRunParameters_WhenProvidingMultipleMultipleTimesTheOptionAndArgument(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--settings my.runsettings --test-parameter MyParameter2=MyValue2 --test-parameter MyParameter3=MyValue3"); // Assert @@ -36,8 +33,7 @@ public async Task TestRunParameters_WhenProvidingMultipleMultipleTimesTheOptionA testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestRunParameters"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadContextTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadContextTests.cs index 596bbd3325..4667b789f7 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadContextTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadContextTests.cs @@ -6,65 +6,67 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class ThreadContextTests : AcceptanceTestBase +[TestClass] +public sealed class ThreadContextTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public ThreadContextTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenCultureIsNotSet_TestMethodFails(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.InitToTestProjectPath, TestAssetFixture.InitToTestProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.InitToTestProjectPath, TestAssetFixture.InitToTestProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertOutputContainsSummary(failed: 1, passed: 0, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenChangedInAssemblyInitialize_IsPassedToTestMethod(string tfm) => await SetCultureInFixtureMethodAndRunTests(tfm, "MSTEST_TEST_SET_CULTURE_ASSEMBLY_INIT"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenChangedInClassInitialize_IsPassedToTestMethod(string tfm) => await SetCultureInFixtureMethodAndRunTests(tfm, "MSTEST_TEST_SET_CULTURE_CLASS_INIT"); - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenChangedInTestInitialize_IsPassedToTestMethod(string tfm) => await SetCultureInFixtureMethodAndRunTests(tfm, "MSTEST_TEST_SET_CULTURE_TEST_INIT"); private async Task SetCultureInFixtureMethodAndRunTests(string tfm, string envVarKey) { - var testHost = TestHost.LocateFrom(_testAssetFixture.InitToTestProjectPath, TestAssetFixture.InitToTestProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.InitToTestProjectPath, TestAssetFixture.InitToTestProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { [envVarKey] = "true" }); testHostResult.AssertExitCodeIs(0); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(0); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenUsingSTAThread_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}"); testHostResult.AssertExitCodeIs(0); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenUsingSTAThreadAndTimeout_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta-timeout.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -74,10 +76,11 @@ public async Task ThreadingContext_WhenUsingSTAThreadAndTimeout_CurrentCultureFl testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_WhenUsingTimeout_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsProjectPath, TestAssetFixture.CultureFlowsProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "timeout.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -87,29 +90,32 @@ public async Task ThreadingContext_WhenUsingTimeout_CurrentCultureFlowsBetweenMe testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_Inheritance_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(0); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 8, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_Inheritance_WhenUsingSTAThread_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}"); testHostResult.AssertExitCodeIs(0); testHostResult.AssertOutputContainsSummary(failed: 0, passed: 8, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_Inheritance_WhenUsingSTAThreadAndTimeout_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta-timeout.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -119,10 +125,11 @@ public async Task ThreadingContext_Inheritance_WhenUsingSTAThreadAndTimeout_Curr testHostResult.AssertOutputContainsSummary(failed: 0, passed: 8, skipped: 0); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task ThreadingContext_Inheritance_WhenUsingTimeout_CurrentCultureFlowsBetweenMethods(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.CultureFlowsInheritanceProjectPath, TestAssetFixture.CultureFlowsInheritanceProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "timeout.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -132,9 +139,7 @@ public async Task ThreadingContext_Inheritance_WhenUsingTimeout_CurrentCultureFl testHostResult.AssertOutputContainsSummary(failed: 0, passed: 8, skipped: 0); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) - : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string InitToTestProjectName = "InitToTestThreadContextProject"; public const string CultureFlowsProjectName = "CultureFlowsThreadContextProject"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadingTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadingTests.cs index b84b167237..393791acf7 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadingTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ThreadingTests.cs @@ -8,25 +8,22 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class ThreadingTests : AcceptanceTestBase +[TestClass] +public sealed class ThreadingTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public ThreadingTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_WhenMainIsNotSTA_NoRunsettingsProvided_ThreadIsNotSTA(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(0); testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnWindows_ThreadIsSTA(string tfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -34,7 +31,7 @@ public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnW return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -45,7 +42,8 @@ public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnW testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnNonWindows_ThreadIsNotSTAAndWarningIsEmitted(string tfm) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -53,7 +51,7 @@ public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnN return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -65,10 +63,11 @@ public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnN testHostResult.AssertOutputContains("Runsettings entry 'STA' is not supported on non-Windows OSes"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForMTA_ThreadIsNotSTA(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -80,7 +79,8 @@ public async Task TestMethodThreading_WhenMainIsNotSTA_RunsettingsAsksForMTA_Thr testHostResult.AssertOutputDoesNotContain("Runsettings entry 'STA' is not supported on non-Windows OSes"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_MainIsSTAThread_OnWindows_NoRunsettingsProvided_ThreadIsSTA(string tfm) { // Test cannot work on non-Windows OSes as the main method is marked with [STAThread] @@ -89,7 +89,7 @@ public async Task TestMethodThreading_MainIsSTAThread_OnWindows_NoRunsettingsPro return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.STAThreadProjectPath, TestAssetFixture.STAThreadProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.STAThreadProjectPath, TestAssetFixture.STAThreadProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(environmentVariables: new() { ["MSTEST_THREAD_STATE_IS_STA"] = "1", @@ -99,7 +99,8 @@ public async Task TestMethodThreading_MainIsSTAThread_OnWindows_NoRunsettingsPro testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_MainIsSTAThread_OnWindows_RunsettingsAsksForSTA_ThreadIsSTA(string tfm) { // Test cannot work on non-Windows OSes as the main method is marked with [STAThread] @@ -108,7 +109,7 @@ public async Task TestMethodThreading_MainIsSTAThread_OnWindows_RunsettingsAsksF return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.STAThreadProjectPath, TestAssetFixture.STAThreadProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.STAThreadProjectPath, TestAssetFixture.STAThreadProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -119,7 +120,8 @@ public async Task TestMethodThreading_MainIsSTAThread_OnWindows_RunsettingsAsksF testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TestMethodThreading_MainIsSTAThread_OnWindows_RunsettingsAsksForMTA_ThreadIsMTA(string tfm) { // Test cannot work on non-Windows OSes as the main method is marked with [STAThread] @@ -128,7 +130,7 @@ public async Task TestMethodThreading_MainIsSTAThread_OnWindows_RunsettingsAsksF return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.STAThreadProjectPath, TestAssetFixture.STAThreadProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.STAThreadProjectPath, TestAssetFixture.STAThreadProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "mta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -139,7 +141,8 @@ public async Task TestMethodThreading_MainIsSTAThread_OnWindows_RunsettingsAsksF testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task LifecycleAttributesVoidThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnWindows_ThreadIsSTA(string tfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -147,7 +150,7 @@ public async Task LifecycleAttributesVoidThreading_WhenMainIsNotSTA_RunsettingsA return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.LifecycleAttributesVoidProjectPath, TestAssetFixture.LifecycleAttributesVoidProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.LifecycleAttributesVoidProjectPath, TestAssetFixture.LifecycleAttributesVoidProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -158,7 +161,8 @@ public async Task LifecycleAttributesVoidThreading_WhenMainIsNotSTA_RunsettingsA testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task LifecycleAttributesTaskThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnWindows_ThreadIsSTA(string tfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -166,7 +170,7 @@ public async Task LifecycleAttributesTaskThreading_WhenMainIsNotSTA_RunsettingsA return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.LifecycleAttributesTaskProjectPath, TestAssetFixture.LifecycleAttributesTaskProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.LifecycleAttributesTaskProjectPath, TestAssetFixture.LifecycleAttributesTaskProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -177,7 +181,8 @@ public async Task LifecycleAttributesTaskThreading_WhenMainIsNotSTA_RunsettingsA testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task LifecycleAttributesTaskThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnWindows_ThreadIsSTA_With_ParallelAttribute(string tfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -185,7 +190,7 @@ public async Task LifecycleAttributesTaskThreading_WhenMainIsNotSTA_RunsettingsA return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.LifecycleAttributesTaskProjectPath, TestAssetFixture.LifecycleWithParallelAttributesTaskProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.LifecycleAttributesTaskProjectPath, TestAssetFixture.LifecycleWithParallelAttributesTaskProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -196,7 +201,8 @@ public async Task LifecycleAttributesTaskThreading_WhenMainIsNotSTA_RunsettingsA testHostResult.AssertOutputContains("Passed!"); } - [ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] public async Task LifecycleAttributesValueTaskThreading_WhenMainIsNotSTA_RunsettingsAsksForSTA_OnWindows_ThreadIsSTA(string tfm) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -204,7 +210,7 @@ public async Task LifecycleAttributesValueTaskThreading_WhenMainIsNotSTA_Runsett return; } - var testHost = TestHost.LocateFrom(_testAssetFixture.LifecycleAttributesValueTaskProjectPath, TestAssetFixture.LifecycleAttributesValueTaskProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.LifecycleAttributesValueTaskProjectPath, TestAssetFixture.LifecycleAttributesValueTaskProjectName, tfm); string runSettingsFilePath = Path.Combine(testHost.DirectoryName, "sta.runsettings"); TestHostResult testHostResult = await testHost.ExecuteAsync($"--settings {runSettingsFilePath}", environmentVariables: new() { @@ -215,9 +221,7 @@ public async Task LifecycleAttributesValueTaskThreading_WhenMainIsNotSTA_Runsett testHostResult.AssertOutputContains("Passed!"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) - : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestThreading"; public const string STAThreadProjectName = "STATestThreading"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs index f2847639e0..59a05bfe2f 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TimeoutTests.cs @@ -7,58 +7,58 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public class TimeoutTests : AcceptanceTestBase +[TestClass] +public class TimeoutTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public TimeoutTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TimeoutWithInvalidArg_WithoutLetterSuffix_OutputInvalidMessage(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TimeoutWithInvalidArg_WithInvalidLetterSuffix_OutputInvalidMessage(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5y"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5h6m"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task Timeout_WhenTimeoutValueSmallerThanTestDuration_OutputContainsCancelingMessage(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 1s"); testHostResult.AssertExitCodeIsNot(ExitCodes.Success); testHostResult.AssertOutputContains("Canceling the test session"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task Timeout_WhenTimeoutValueGreaterThanTestDuration_OutputDoesNotContainCancelingMessage(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 30s"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -66,8 +66,7 @@ public async Task Timeout_WhenTimeoutValueGreaterThanTestDuration_OutputDoesNotC testHostResult.AssertOutputDoesNotContain("Canceling the test session"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string AssetName = "TimeoutTest"; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ValueTaskTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ValueTaskTests.cs index 110cfc716e..acaed7964b 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ValueTaskTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ValueTaskTests.cs @@ -6,18 +6,14 @@ namespace MSTest.Acceptance.IntegrationTests; -[TestGroup] -public sealed class ValueTaskTests : AcceptanceTestBase +[TestClass] +public sealed class ValueTaskTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public ValueTaskTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [TestMethod] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] public async Task CanUseValueTaskForAllKnownLocations(string tfm) { - var testHost = TestHost.LocateFrom(_testAssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); + var testHost = TestHost.LocateFrom(AssetFixture.ProjectPath, TestAssetFixture.ProjectName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); // Assert @@ -25,8 +21,7 @@ public async Task CanUseValueTaskForAllKnownLocations(string tfm) testHostResult.AssertOutputContainsSummary(failed: 1, passed: 2, skipped: 1); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string ProjectName = "TestValueTask"; diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AbortionTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AbortionTests.cs index 3938ea7cf8..80d9cfb1a0 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AbortionTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AbortionTests.cs @@ -3,22 +3,16 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class AbortionTests : AcceptanceTestBase +[TestClass] +public class AbortionTests : AcceptanceTestBase { private const string AssetName = "Abort"; - private readonly TestAssetFixture _testAssetFixture; - - public AbortionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; // We retry because sometime the Canceling the session message is not showing up. - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task AbortWithCTRLPlusC_TestHost_Succeeded(string tfm) { // We expect the same semantic for Linux, the test setup is not cross and we're using specific @@ -28,14 +22,14 @@ public async Task AbortWithCTRLPlusC_TestHost_Succeeded(string tfm) return; } - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.TestSessionAborted); // We check only in netcore for netfx is now showing in CI every time, the same behavior in local something works sometime nope. // Manual test works pretty always as expected, looks like the implementation is different, we care more on .NET Core. - if (TargetFrameworks.Net.Select(x => x.Arguments).Contains(tfm)) + if (TargetFrameworks.Net.Contains(tfm)) { testHostResult.AssertOutputMatchesRegex("Canceling the test session.*"); } @@ -43,8 +37,7 @@ public async Task AbortWithCTRLPlusC_TestHost_Succeeded(string tfm) testHostResult.AssertOutputContainsSummary(failed: 0, passed: 0, skipped: 0, aborted: true); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string Sources = """ #file Abort.csproj @@ -78,11 +71,11 @@ internal sealed class Program public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter()); + builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); _ = Task.Run(() => { - DummyAdapter.FireCancel.Wait(); + DummyTestFramework.FireCancel.Wait(); if (!GenerateConsoleCtrlEvent(ConsoleCtrlEvent.CTRL_C, 0)) { @@ -105,10 +98,10 @@ public enum ConsoleCtrlEvent } -internal class DummyAdapter : ITestFramework, IDataProducer +internal class DummyTestFramework : ITestFramework, IDataProducer { public static readonly ManualResetEventSlim FireCancel = new ManualResetEventSlim(false); - public string Uid => nameof(DummyAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => string.Empty; @@ -118,9 +111,11 @@ internal class DummyAdapter : ITestFramework, IDataProducer public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) }; - public Task CloseTestSessionAsync(CloseTestSessionContext context) => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); - public Task CreateTestSessionAsync(CreateTestSessionContext context) => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); public async Task ExecuteRequestAsync(ExecuteRequestContext context) { diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashDumpTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashDumpTests.cs index cad2f04a15..5805981732 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashDumpTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashDumpTests.cs @@ -3,20 +3,13 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed class CrashDumpTests : AcceptanceTestBase +[TestClass] +public sealed class CrashDumpTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public CrashDumpTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task CrashDump_DefaultSetting_CreateDump(string tfm) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -25,14 +18,15 @@ public async Task CrashDump_DefaultSetting_CreateDump(string tfm) return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", tfm); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", tfm); TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --results-directory {resultDirectory}"); testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully); string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump.dll_*.dmp", SearchOption.AllDirectories).SingleOrDefault(); Assert.IsTrue(dumpFile is not null, $"Dump file not found '{tfm}'\n{testHostResult}'"); } + [TestMethod] public async Task CrashDump_CustomDumpName_CreateDump() { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -41,17 +35,18 @@ public async Task CrashDump_CustomDumpName_CreateDump() return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-filename customdumpname.dmp --results-directory {resultDirectory}"); testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully); Assert.IsTrue(Directory.GetFiles(resultDirectory, "customdumpname.dmp", SearchOption.AllDirectories).SingleOrDefault() is not null, "Dump file not found"); } - [Arguments("Mini")] - [Arguments("Heap")] - [Arguments("Triage")] - [Arguments("Full")] + [DataRow("Mini")] + [DataRow("Heap")] + [DataRow("Triage")] + [DataRow("Full")] + [TestMethod] public async Task CrashDump_Formats_CreateDump(string format) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -60,8 +55,8 @@ public async Task CrashDump_Formats_CreateDump(string format) return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type {format} --results-directory {resultDirectory}"); testHostResult.AssertExitCodeIs(ExitCodes.TestHostProcessExitedNonGracefully); string? dumpFile = Directory.GetFiles(resultDirectory, "CrashDump.dll_*.dmp", SearchOption.AllDirectories).SingleOrDefault(); @@ -69,17 +64,17 @@ public async Task CrashDump_Formats_CreateDump(string format) File.Delete(dumpFile); } + [TestMethod] public async Task CrashDump_InvalidFormat_ShouldFail() { - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N")); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync($"--crashdump --crashdump-type invalid --results-directory {resultDirectory}"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("Option '--crashdump-type' has invalid arguments: 'invalid' is not a valid dump type. Valid options are 'Mini', 'Heap', 'Triage' and 'Full'"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string AssetName = "CrashDumpFixture"; @@ -130,22 +125,22 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); builder.AddCrashDumpProvider(); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework +public class DummyTestFramework : ITestFramework { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashPlusHangDumpTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashPlusHangDumpTests.cs index 8d4a1adca5..56ad9445d5 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashPlusHangDumpTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CrashPlusHangDumpTests.cs @@ -3,19 +3,12 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed class CrashPlusHangDumpTests : AcceptanceTestBase +[TestClass] +public sealed class CrashPlusHangDumpTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public CrashPlusHangDumpTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task CrashPlusHangDump_InCaseOfCrash_CreateCrashDump() { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -24,8 +17,8 @@ public async Task CrashPlusHangDump_InCaseOfCrash_CreateCrashDump() return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 5m --crashdump --results-directory {resultDirectory}", new Dictionary @@ -43,6 +36,7 @@ public async Task CrashPlusHangDump_InCaseOfCrash_CreateCrashDump() Assert.IsFalse(Directory.GetFiles(resultDirectory, "CrashPlusHangDump*_hang.dmp", SearchOption.AllDirectories).Length > 0, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'"); } + [TestMethod] public async Task CrashPlusHangDump_InCaseOfHang_CreateHangDump() { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -51,8 +45,8 @@ public async Task CrashPlusHangDump_InCaseOfHang_CreateHangDump() return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "CrashPlusHangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 8s --crashdump --results-directory {resultDirectory}", new Dictionary @@ -70,10 +64,9 @@ public async Task CrashPlusHangDump_InCaseOfHang_CreateHangDump() Assert.IsTrue(Directory.GetFiles(resultDirectory, "CrashPlusHangDump*_hang.dmp", SearchOption.AllDirectories).Length > 0, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { - private const string AssetName = "TestAssetFixture"; + private const string AssetName = "AssetFixture"; public string TargetAssetPath => GetAssetPath(AssetName); @@ -123,7 +116,7 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); builder.AddCrashDumpProvider(); builder.AddHangDumpProvider(); using ITestApplication app = await builder.BuildAsync(); @@ -131,15 +124,15 @@ public static async Task Main(string[] args) } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CustomBannerTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CustomBannerTests.cs index 4c3920dbfd..9239a51a4a 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CustomBannerTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/CustomBannerTests.cs @@ -1,34 +1,29 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class CustomBannerTests : AcceptanceTestBase +[TestClass] +public class CustomBannerTests : AcceptanceTestBase { private const string AssetName = "CustomBannerTest"; - private readonly TestAssetFixture _testAssetFixture; - - public CustomBannerTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task UsingNoBanner_TheBannerDoesNotAppear(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--no-banner"); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); testHostResult.AssertOutputDoesNotContain(TestAssetFixture.CustomBannerPrefix); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task UsingNoBanner_InTheEnvironmentVars_TheBannerDoesNotAppear(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -40,10 +35,11 @@ public async Task UsingNoBanner_InTheEnvironmentVars_TheBannerDoesNotAppear(stri testHostResult.AssertOutputDoesNotContain(TestAssetFixture.CustomBannerPrefix); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task UsingDotnetNoLogo_InTheEnvironmentVars_TheBannerDoesNotAppear(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -55,18 +51,18 @@ public async Task UsingDotnetNoLogo_InTheEnvironmentVars_TheBannerDoesNotAppear( testHostResult.AssertOutputDoesNotContain(TestAssetFixture.CustomBannerPrefix); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task WithoutUsingNoBanner_TheBannerAppears(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); testHostResult.AssertOutputMatchesRegex($"{TestAssetFixture.CustomBannerPrefix} Platform info: Name: .NET Testing Platform, Version: .+?, Hash: .*?, Date: .+?"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string CustomBannerPrefix = "Custom banner |"; @@ -102,7 +98,7 @@ public static async Task Main(string[] args) ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); builder.RegisterTestFramework( sp => new TestFrameworkCapabilities(new DummyBannerMessageOwnerCapability(sp)), - (_,__) => new DummyTestAdapter()); + (_,__) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } @@ -128,20 +124,20 @@ public DummyBannerMessageOwnerCapability(IServiceProvider serviceProvider) sb.Append($", Hash: {platformInformation.CommitHash}"); sb.Append($", Date: {platformInformation.BuildDate}"); - return Task.FromResult(sb.ToString()); + return Task.FromResult(sb.ToString()); } } #pragma warning restore TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. -public class DummyTestAdapter : ITestFramework +public class DummyTestFramework : ITestFramework { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs index 65eaeb6028..d584878a83 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs @@ -3,111 +3,112 @@ using System.Text.RegularExpressions; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; using Microsoft.Testing.Platform.Configurations; -using Microsoft.Testing.Platform.Helpers; namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class DiagnosticTests : AcceptanceTestBase +[TestClass] +public class DiagnosticTests : AcceptanceTestBase { private const string AssetName = "DiagnosticTest"; - private readonly TestAssetFixture _testAssetFixture; - - public DiagnosticTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticIsSpecified_ReportIsGeneratedInDefaultLocation(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic"); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticAndOutputFilePrefixAreSpecified_ReportIsGeneratedInDefaultLocation(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"abcd_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic --diagnostic-output-fileprefix abcd"); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticAndOutputDirectoryAreSpecified_ReportIsGeneratedInSpecifiedLocation(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, "test1"); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, "test1"); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); Assert.IsTrue(Directory.CreateDirectory(diagPath).Exists); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync($"--diagnostic --diagnostic-output-directory {diagPath}"); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticAndOutputFilePrefixAndOutputDirectoryAreSpecified_ReportIsGeneratedInSpecifiedLocation(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, "test2"); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, "test2"); string diagPathPattern = Path.Combine(diagPath, @"abcde_.*.diag").Replace(@"\", @"\\"); Assert.IsTrue(Directory.CreateDirectory(diagPath).Exists); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync($"--diagnostic --diagnostic-output-fileprefix abcde --diagnostic-output-directory {diagPath}"); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticOutputFilePrefixButNotDiagnosticIsSpecified_ReportGenerationFails(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic-output-fileprefix cccc"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("'--diagnostic-output-fileprefix' requires '--diagnostic' to be provided"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticOutputDirectoryButNotDiagnosticIsSpecified_ReportGenerationFails(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic-output-directory cccc"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("'--diagnostic-output-directory' requires '--diagnostic' to be provided"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_WhenDiagnosticFilePrefixAndDiagnosticOutputDirectoryButNotDiagnosticAreSpecified_ReportGenerationFails(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic-output-fileprefix aaaa --diagnostic-output-directory cccc"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.AssertOutputContains("'--diagnostic-output-directory' requires '--diagnostic' to be provided"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_Succeeded(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -118,13 +119,14 @@ public async Task Diag_EnableWithEnvironmentVariables_Succeeded(string tfm) await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_Verbosity_Succeeded(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -136,13 +138,14 @@ public async Task Diag_EnableWithEnvironmentVariables_Verbosity_Succeeded(string await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_Succeeded(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"MyPrefix_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -154,13 +157,14 @@ public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_Succeeded(str await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_Succeeded(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -172,10 +176,11 @@ public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_Succeeded await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern, flushType: "sync"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_Disable_Succeeded(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--diagnostic", @@ -183,17 +188,17 @@ public async Task Diag_EnableWithEnvironmentVariables_Disable_Succeeded(string t { { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC, "0" }, }); - testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); testHostResult.AssertOutputDoesNotContain("Diagnostic file"); testHostResult = await testHost.ExecuteAsync("--diagnostic"); - testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); testHostResult.AssertOutputContains("Diagnostic file"); } private async Task AssertDiagnosticReportWasGeneratedAsync(TestHostResult testHostResult, string diagPathPattern, string level = "Trace", string flushType = "async") { - testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); string outputPattern = $""" Diagnostic file \(level '{level}' with {flushType} flush\): {diagPathPattern} @@ -222,8 +227,7 @@ private async Task AssertDiagnosticReportWasGeneratedAsync(TestHostResul return (Regex.IsMatch(content, pattern), content); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string TestCode = """ #file DiagnosticTest.csproj @@ -237,37 +241,51 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test preview - - - - #file Program.cs -using DiagnosticTest; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace DiagnosticTest; +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Services; -[TestGroup] -public class UnitTest1 +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,__) => new DummyTestFramework()); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } } -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Extensions; +public class DummyTestFramework : ITestFramework +{ + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); + + public string Description => nameof(DummyTestFramework); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + public Task ExecuteRequestAsync(ExecuteRequestContext context) + { + context.Complete(); + return Task.CompletedTask; + } +} """; public string TargetAssetPath => GetAssetPath(AssetName); @@ -278,8 +296,7 @@ public void TestMethod1() TestCode .PatchTargetFrameworks(TargetFrameworks.All) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); } } } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/EnvironmentVariablesConfigurationProviderTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/EnvironmentVariablesConfigurationProviderTests.cs index 5b8e45a901..1da20468e9 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/EnvironmentVariablesConfigurationProviderTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/EnvironmentVariablesConfigurationProviderTests.cs @@ -1,31 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed class EnvironmentVariablesConfigurationProviderTests : AcceptanceTestBase +[TestClass] +public sealed class EnvironmentVariablesConfigurationProviderTests : AcceptanceTestBase { private const string AssetName = "EnvironmentVariablesConfigurationProvider"; - private readonly TestAssetFixture _testAssetFixture; - - public EnvironmentVariablesConfigurationProviderTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task SetEnvironmentVariable_ShouldSucceed(string currentTfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.Success); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) - : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string Sources = """ #file EnvironmentVariablesConfigurationProvider.csproj @@ -63,7 +55,7 @@ public class Startup public static async Task Main(string[] args) { var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); - testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); testApplicationBuilder.TestHostControllers.AddEnvironmentVariableProvider(_ => new TestHostEnvironmentVariableProviderTestClass()); using ITestApplication app = await testApplicationBuilder.BuildAsync(); return await app.RunAsync(); @@ -97,15 +89,15 @@ public Task ValidateTestHostEnvironmentVariablesAsync(IReadOnl } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs index b925c1cefc..235c2c376d 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs @@ -3,121 +3,115 @@ using System.Diagnostics; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class ExecutionTests : AcceptanceTestBase +[TestClass] +public class ExecutionTests : AcceptanceTestBase { private const string AssetName = "ExecutionTests"; private const string AssetName2 = "ExecutionTests2"; - private readonly TestAssetFixture _testAssetFixture; - - public ExecutionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenListTestsIsSpecified_AllTestsAreFound(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests"); testHostResult.AssertExitCodeIs(ExitCodes.Success); const string OutputPattern = """ The following Tests are available: -TestMethod1 -TestMethod2 -TestMethod3 -FilteredOutTest$ +Test1 +Test2$ """; testHostResult.AssertOutputMatchesRegex(OutputPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenOnlyAssetNameIsSpecified_AllTestsAreRun(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.Success); - testHostResult.AssertOutputContainsSummary(failed: 0, passed: 4, skipped: 0); - testHostResult.AssertOutputContains($"! - {_testAssetFixture.TargetAssetPath}"); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 2, skipped: 0); + testHostResult.AssertOutputContains($"! - {AssetFixture.TargetAssetPath}"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenListTestsAndFilterAreSpecified_OnlyFilteredTestsAreFound(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); - TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests --treenode-filter \"/ExecutionTests/ExecutionTests/UnitTest1/TestMethod*\""); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests --treenode-filter \"\""); testHostResult.AssertExitCodeIs(ExitCodes.Success); const string OutputPattern = """ The following Tests are available: -TestMethod1 -TestMethod2 -TestMethod3$ +Test1$ """; testHostResult.AssertOutputMatchesRegex(OutputPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); - TestHostResult testHostResult = await testHost.ExecuteAsync("--treenode-filter \"/ExecutionTests/ExecutionTests/UnitTest1/TestMethod*\""); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync("--treenode-filter \"\""); testHostResult.AssertExitCodeIs(ExitCodes.Success); - testHostResult.AssertOutputContainsSummary(failed: 0, passed: 3, skipped: 0); - testHostResult.AssertOutputContains($"! - {_testAssetFixture.TargetAssetPath}"); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); + testHostResult.AssertOutputContains($"! - {AssetFixture.TargetAssetPath}"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenMinimumExpectedTestsIsSpecifiedAndEnoughTestsRun_ResultIsOk(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); - TestHostResult testHostResult = await testHost.ExecuteAsync("--minimum-expected-tests 4"); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync("--minimum-expected-tests 2"); testHostResult.AssertExitCodeIs(ExitCodes.Success); - testHostResult.AssertOutputContainsSummary(failed: 0, passed: 4, skipped: 0); - testHostResult.AssertOutputContains($"! - {_testAssetFixture.TargetAssetPath}"); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 2, skipped: 0); + testHostResult.AssertOutputContains($"! - {AssetFixture.TargetAssetPath}"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenMinimumExpectedTestsIsSpecifiedAndNotEnoughTestsRun_ResultIsNotOk(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); - TestHostResult testHostResult = await testHost.ExecuteAsync("--minimum-expected-tests 5"); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync("--minimum-expected-tests 3"); testHostResult.AssertExitCodeIs(ExitCodes.MinimumExpectedTestsPolicyViolation); - testHostResult.AssertOutputContainsSummary(failed: 0, passed: 4, skipped: 0, minimumNumberOfTests: 5); - testHostResult.AssertOutputContains($" - {_testAssetFixture.TargetAssetPath}"); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 2, skipped: 0, minimumNumberOfTests: 3); + testHostResult.AssertOutputContains($" - {AssetFixture.TargetAssetPath}"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_WhenListTestsAndMinimumExpectedTestsAreSpecified_DiscoveryFails(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); - TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests --minimum-expected-tests 4"); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests --minimum-expected-tests 2"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); - - const string OutputPattern = "Error: '--list-tests' and '--minimum-expected-tests' are incompatible options"; - Assert.That(testHostResult.StandardOutput.Contains(OutputPattern), $"Output of the test host is:\n{testHostResult}"); + testHostResult.AssertOutputContains("Error: '--list-tests' and '--minimum-expected-tests' are incompatible options"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Exec_Honor_Request_Complete(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath2, AssetName2, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath2, AssetName2, tfm); var stopwatch = Stopwatch.StartNew(); TestHostResult testHostResult = await testHost.ExecuteAsync(); stopwatch.Stop(); @@ -125,8 +119,7 @@ public async Task Exec_Honor_Request_Complete(string tfm) Assert.IsTrue(stopwatch.Elapsed.TotalSeconds > 3); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string TestCode = """ #file ExecutionTests.csproj @@ -140,52 +133,92 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test preview - - - - #file Program.cs -using ExecutionTests; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace ExecutionTests; +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions; +using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Helpers; +using Microsoft.Testing.Platform.Services; -[TestGroup] -public class UnitTest1 +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + MyExtension myExtension = new(); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,sp) => new DummyTestFramework(sp, myExtension)); + builder.AddTreeNodeFilterService(myExtension); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } +} - public void TestMethod2() - { - Assert.IsTrue(true); - } +public class MyExtension : IExtension +{ + public string Uid => "MyExtension"; + public string Version => "1.0.0"; + public string DisplayName => "My Extension"; + public string Description => "My Extension Description"; + public Task IsEnabledAsync() => Task.FromResult(true); +} + +public class DummyTestFramework : ITestFramework, IDataProducer +{ + private IServiceProvider _sp; + private MyExtension _myExtension; - public void TestMethod3() + public DummyTestFramework(IServiceProvider sp, MyExtension myExtension) { - Assert.IsTrue(true); + _sp = sp; + _myExtension = myExtension; } - public void FilteredOutTest() + public string Uid => _myExtension.Uid; + + public string Version => _myExtension.Version; + + public string DisplayName => _myExtension.DisplayName; + + public string Description => _myExtension.Description; + + public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)]; + + public Task IsEnabledAsync() => _myExtension.IsEnabledAsync(); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + + public async Task ExecuteRequestAsync(ExecuteRequestContext context) { - Assert.IsTrue(true); + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "0", DisplayName = "Test1", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "0", DisplayName = "Test1", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); + + if (!_sp.GetCommandLineOptions().TryGetOptionArgumentList("--treenode-filter", out _)) + { + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "1", DisplayName = "Test2", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "1", DisplayName = "Test2", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); + } + + context.Complete(); } } - -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Extensions; """; private const string TestCode2 = """ @@ -215,13 +248,13 @@ public void FilteredOutTest() using System.Threading.Tasks; ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter()); +builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); -internal class DummyAdapter : ITestFramework, IDataProducer +internal class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => string.Empty; @@ -271,8 +304,7 @@ internal class Capabilities : ITestFrameworkCapabilities TestCode .PatchTargetFrameworks(TargetFrameworks.All) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); yield return (AssetName2, AssetName2, TestCode2 diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExitOnProcessExitTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExitOnProcessExitTests.cs index 98b741b9e9..d7382cc3b0 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExitOnProcessExitTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExitOnProcessExitTests.cs @@ -5,19 +5,16 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class ExitOnProcessExitTests : AcceptanceTestBase +[TestClass] +public class ExitOnProcessExitTests : AcceptanceTestBase { private const string AssetName = "ExecutionTests"; - private readonly TestAssetFixture _testAssetFixture; - public ExitOnProcessExitTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public void ExitOnProcessExit_Succeed(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); // Create the mutex name used to wait for the PID file created by the test host. string waitPid = Guid.NewGuid().ToString("N"); @@ -60,8 +57,7 @@ public void ExitOnProcessExit_Succeed(string tfm) } } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string TestCode = """ #file ExecutionTests.csproj @@ -115,21 +111,21 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test else { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpOutputTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpOutputTests.cs index a66c6d166f..a46fd94340 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpOutputTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpOutputTests.cs @@ -3,20 +3,13 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed class HangDumpOutputTests : AcceptanceTestBase +[TestClass] +public sealed class HangDumpOutputTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public HangDumpOutputTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [Arguments("Mini")] + [DataRow("Mini")] + [TestMethod] public async Task HangDump_Outputs_HangingTests_EvenWhenHangingTestsHaveTheSameDisplayName(string format) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -30,8 +23,8 @@ public async Task HangDump_Outputs_HangingTests_EvenWhenHangingTestsHaveTheSameD // a dictionary based on DisplayName. In that case both tests were started at the same time, and only 1 entry was added // to currently executing tests. When first test with name Test1 completed we removed that entry, but Class2.Test1 was still // running. Solution is to use a more unique identifier. - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), format); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), format); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 8s --hangdump-type {format} --results-directory {resultDirectory} --no-progress", new Dictionary @@ -43,10 +36,9 @@ public async Task HangDump_Outputs_HangingTests_EvenWhenHangingTestsHaveTheSameD testHostResult.AssertOutputContains("Test1"); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { - private const string AssetName = "TestAssetFixture"; + private const string AssetName = "AssetFixture"; public string TargetAssetPath => GetAssetPath(AssetName); @@ -96,22 +88,22 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); builder.AddHangDumpProvider(); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpTests.cs index fc9935efce..15d4bfe244 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HangDumpTests.cs @@ -3,20 +3,13 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed class HangDumpTests : AcceptanceTestBase +[TestClass] +public sealed class HangDumpTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public HangDumpTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task HangDump_DefaultSetting_CreateDump(string tfm) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -25,8 +18,8 @@ public async Task HangDump_DefaultSetting_CreateDump(string tfm) return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", tfm); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDump", tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 8s --results-directory {resultDirectory}", new Dictionary @@ -39,6 +32,7 @@ public async Task HangDump_DefaultSetting_CreateDump(string tfm) Assert.IsTrue(dumpFile is not null, $"Dump file not found '{tfm}'\n{testHostResult}'"); } + [TestMethod] public async Task HangDump_CustomFileName_CreateDump() { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -47,8 +41,8 @@ public async Task HangDump_CustomFileName_CreateDump() return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 8s --hangdump-filename myhungdumpfile_%p.dmp --results-directory {resultDirectory}", new Dictionary @@ -61,6 +55,7 @@ public async Task HangDump_CustomFileName_CreateDump() Assert.IsTrue(dumpFile is not null, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'"); } + [TestMethod] public async Task HangDump_PathWithSpaces_CreateDump() { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -69,10 +64,10 @@ public async Task HangDump_PathWithSpaces_CreateDump() return; } - string resultDir = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments); + string resultDir = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent); string resultDirectory = Path.Combine(resultDir, "directory with spaces"); Directory.CreateDirectory(resultDirectory); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"""--hangdump --hangdump-timeout 8s --hangdump-filename myhungdumpfile_%p.dmp --results-directory "{resultDirectory}" """, new Dictionary @@ -85,10 +80,11 @@ public async Task HangDump_PathWithSpaces_CreateDump() Assert.IsTrue(dumpFile is not null, $"Dump file not found '{TargetFrameworks.NetCurrent}'\n{testHostResult}'"); } - [Arguments("Mini")] - [Arguments("Heap")] - [Arguments("Triage")] - [Arguments("Full")] + [DataRow("Mini")] + [DataRow("Heap")] + [DataRow("Triage")] + [DataRow("Full")] + [TestMethod] public async Task HangDump_Formats_CreateDump(string format) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -97,8 +93,8 @@ public async Task HangDump_Formats_CreateDump(string format) return; } - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), format); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), format); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 8s --hangdump-type {format} --results-directory {resultDirectory}", new Dictionary @@ -111,10 +107,11 @@ public async Task HangDump_Formats_CreateDump(string format) Assert.IsTrue(dumpFile is not null, $"Dump file not found '{format}'\n{testHostResult}'"); } + [TestMethod] public async Task HangDump_InvalidFormat_ShouldFail() { - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent.Arguments); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent.Arguments); + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), TargetFrameworks.NetCurrent); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "HangDump", TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--hangdump --hangdump-timeout 8s --hangdump-type invalid --results-directory {resultDirectory}", new Dictionary @@ -129,10 +126,9 @@ public async Task HangDump_InvalidFormat_ShouldFail() """); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { - private const string AssetName = "TestAssetFixture"; + private const string AssetName = "AssetFixture"; public string TargetAssetPath => GetAssetPath(AssetName); @@ -182,22 +178,22 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); builder.AddHangDumpProvider(); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs index 1f66b97679..5c6f2f5b98 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -1,23 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class HelpInfoTests : AcceptanceTestBase +[TestClass] +public class HelpInfoTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public HelpInfoTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Help_WhenNoExtensionRegistered_OutputDefaultHelpContent(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--help"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -72,17 +65,16 @@ Disable reporting progress to screen. --output Output verbosity when reporting tests. Valid values are 'Normal', 'Detailed'. Default is 'Normal'. - --treenode-filter - Use a tree filter to filter down the tests to execute """; testHostResult.AssertOutputMatchesLines(wildcardMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task HelpShortName_WhenNoExtensionRegistered_OutputDefaultHelpContent(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--?"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -97,12 +89,13 @@ Execute a .NET Test Application. testHostResult.AssertOutputMatchesLines(wildcardMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Help_WhenNoExtensionRegisteredAndUnknownOptionIsSpecified_OutputDefaultHelpContentAndUnknownOption(string tfm) { const string UnknownOption = "aaa"; - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync($"-{UnknownOption}"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); @@ -118,10 +111,11 @@ Execute a .NET Test Application. testHostResult.AssertOutputMatchesLines(wildcardMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Info_WhenNoExtensionRegistered_OutputDefaultInfoContent(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.NoExtensionAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--info"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -132,7 +126,7 @@ .NET Testing Platform v.+ \[.+\] Version: .+ Dynamic Code Supported: True Runtime information: .+ - {(tfm != TargetFrameworks.NetFramework[0].Arguments ? "###SKIP###" : $"Runtime location: .+")} + {(tfm != TargetFrameworks.NetFramework[0] ? "###SKIP###" : $"Runtime location: .+")} Test module: .+{TestAssetFixture.NoExtensionAssetName}.* Built-in command line providers: PlatformCommandLineProvider @@ -260,15 +254,6 @@ Takes one argument as string in the format \[h\|m\|s\] where 'value' is f Hidden: False Description: Output verbosity when reporting tests. Valid values are 'Normal', 'Detailed'. Default is 'Normal'. - TestingFrameworkExtension - Name: Microsoft Testing Framework - Version: .+ - Description: Microsoft Testing Framework\. This framework allows you to test your code anywhere in any mode \(all OSes, all platforms, all configurations\.\.\.\)\. - Options: - --treenode-filter - Arity: 1 - Hidden: False - Description: Use a tree filter to filter down the tests to execute Registered tools: There are no registered tools\. """; @@ -276,10 +261,11 @@ There are no registered tools\. testHostResult.AssertOutputMatchesRegexLines(regexMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Help_WithAllExtensionsRegistered_OutputFullHelpContent(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--help"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -367,17 +353,16 @@ Output verbosity when reporting tests. Enable generating TRX report --report-trx-filename The name of the generated TRX report - --treenode-filter - Use a tree filter to filter down the tests to execute """; testHostResult.AssertOutputMatchesLines(wildcardPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task HelpShortName_WithAllExtensionsRegistered_OutputFullHelpContent(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("-?"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -392,10 +377,11 @@ Execute a .NET Test Application. testHostResult.AssertOutputMatchesLines(wildcardPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Info_WithAllExtensionsRegistered_OutputFullInfoContent(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.AllExtensionsTargetAssetPath, TestAssetFixture.AllExtensionsAssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--info"); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -406,7 +392,7 @@ .NET Testing Platform v* [*] Version: * Dynamic Code Supported: True Runtime information: * - {(tfm != TargetFrameworks.NetFramework[0].Arguments ? "###SKIP###" : $"Runtime location: *")} + {(tfm != TargetFrameworks.NetFramework[0] ? "###SKIP###" : $"Runtime location: *")} Test module: *{TestAssetFixture.AllExtensionsAssetName}* Built-in command line providers: PlatformCommandLineProvider @@ -563,6 +549,15 @@ Default is 30m. Description: Specify the type of the dump. Valid values are 'Mini', 'Heap', 'Triage' (only available in .NET 6+) or 'Full'. Default type is 'Full' + MSBuildCommandLineProvider + Name: MSBuildCommandLineProvider + Version: * + Description: Extension used to pass parameters from MSBuild node and the hosts + Options: + --internal-msbuild-node + Arity: 1 + Hidden: True + Description: Used to pass the MSBuild node handle RetryCommandLineOptionsProvider Name: Retry failed tests Version: * @@ -602,15 +597,6 @@ Default type is 'Full' Hidden: False Description: Output verbosity when reporting tests. Valid values are 'Normal', 'Detailed'. Default is 'Normal'. - TestingFrameworkExtension - Name: Microsoft Testing Framework - Version: * - Description: Microsoft Testing Framework. This framework allows you to test your code anywhere in any mode (all OSes, all platforms, all configurations...). - Options: - --treenode-filter - Arity: 1 - Hidden: False - Description: Use a tree filter to filter down the tests to execute TrxReportGeneratorCommandLine Name: TRX report generator Version: * @@ -649,8 +635,7 @@ Default type is 'Full' testHostResult.AssertOutputMatchesLines(wildcardPattern); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string AllExtensionsAssetName = "AllExtensionsInfoTest"; public const string NoExtensionAssetName = "NoExtensionInfoTest"; @@ -664,13 +649,10 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test enable Exe preview + false - - - - - + @@ -680,33 +662,47 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test #file Program.cs -using AllExtensionsInfoTest; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -builder.AddCrashDumpProvider(); -builder.AddHangDumpProvider(); -builder.AddHotReloadProvider(); -builder.AddRetryProvider(); -builder.AddTrxReportProvider(); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace AllExtensionsInfoTest; - -[TestGroup] -public class UnitTest1 +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Services; + +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,__) => new DummyTestFramework()); + builder.AddSelfRegisteredExtensions(args); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } } -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Extensions; +public class DummyTestFramework : ITestFramework +{ + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); + + public string Description => nameof(DummyTestFramework); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + public Task ExecuteRequestAsync(ExecuteRequestContext context) + { + context.Complete(); + return Task.CompletedTask; + } +} """; private const string NoExtensionTestCode = """ @@ -721,37 +717,51 @@ public void TestMethod1() preview - - - - #file Program.cs -using NoExtensionInfoTest; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace NoExtensionInfoTest; +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Services; -[TestGroup] -public class UnitTest1 +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,__) => new DummyTestFramework()); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } } -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Extensions; +public class DummyTestFramework : ITestFramework +{ + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); + + public string Description => nameof(DummyTestFramework); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + public Task ExecuteRequestAsync(ExecuteRequestContext context) + { + context.Complete(); + return Task.CompletedTask; + } +} """; public string NoExtensionTargetAssetPath => GetAssetPath(NoExtensionAssetName); @@ -764,14 +774,12 @@ public void TestMethod1() NoExtensionTestCode .PatchTargetFrameworks(TargetFrameworks.All) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); yield return (AllExtensionsAssetName, AllExtensionsAssetName, AllExtensionsTestCode .PatchTargetFrameworks(TargetFrameworks.All) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); } } } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceAssert.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceAssert.cs index a5ec05d244..737af51263 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceAssert.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceAssert.cs @@ -10,10 +10,10 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; internal static class AcceptanceAssert { public static void AssertExitCodeIs(this TestHostResult testHostResult, int exitCode, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(exitCode == testHostResult.ExitCode, GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => Assert.AreEqual(exitCode, testHostResult.ExitCode, GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); public static void AssertExitCodeIsNot(this TestHostResult testHostResult, int exitCode, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(exitCode != testHostResult.ExitCode, GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => Assert.AreNotEqual(exitCode, testHostResult.ExitCode, GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); /// /// Ensure that the output matches the given pattern. The pattern can use `*` to mean any character, it is internally replaced by `.*` and matched as regex. @@ -40,22 +40,15 @@ public static void AssertOutputMatchesLines(this TestHostResult testHostResult, + Regex.Escape(wildcardLines[i]).Replace("\\*", ".*") + "$"; - Assert.That( + Assert.IsTrue( Regex.IsMatch(outputLine, matchingPatternLine, RegexOptions.Singleline), - $"Output on line {j + 1}{Environment.NewLine}{outputLine}{Environment.NewLine}doesn't match pattern{Environment.NewLine}{matchingPatternLine}{Environment.NewLine}Standard output:{Environment.NewLine}{testHostResult.StandardOutput}", - callerMemberName: callerMemberName, - callerFilePath: callerFilePath, - callerLineNumber: callerLineNumber); + $"Output on line {j + 1}{Environment.NewLine}{outputLine}{Environment.NewLine}doesn't match pattern{Environment.NewLine}{matchingPatternLine}{Environment.NewLine}Standard output:{Environment.NewLine}{testHostResult.StandardOutput}{Environment.NewLine}for member '{callerMemberName}' at line {callerLineNumber} of file '{callerFilePath}'."); } else { string expectedLine = wildcardLines[i]; - Assert.That( - string.Equals(outputLine, expectedLine, StringComparison.Ordinal), - $"Output on line {j + 1} (length: {outputLine.Length}){Environment.NewLine}{outputLine}{Environment.NewLine}doesn't match line (length: {expectedLine.Length}){Environment.NewLine}{expectedLine}{Environment.NewLine}Standard output:{Environment.NewLine}{testHostResult.StandardOutput}", - callerMemberName: callerMemberName, - callerFilePath: callerFilePath, - callerLineNumber: callerLineNumber); + Assert.AreEqual(expectedLine, outputLine, StringComparer.Ordinal, + $"Output on line {j + 1} (length: {outputLine.Length}){Environment.NewLine}{outputLine}{Environment.NewLine}doesn't match line (length: {expectedLine.Length}){Environment.NewLine}{expectedLine}{Environment.NewLine}Standard output:{Environment.NewLine}{testHostResult.StandardOutput}{Environment.NewLine}for member '{callerMemberName}' at line {callerLineNumber} of file '{callerFilePath}'."); } j++; @@ -79,42 +72,39 @@ public static void AssertOutputMatchesRegexLines(this TestHostResult testHostRes } string outputLine = testHostResult.StandardOutputLines[j]; - Assert.That( + Assert.IsTrue( Regex.IsMatch(outputLine, patternLines[i], RegexOptions.Singleline), - $"Output on line {j + 1}{Environment.NewLine}{outputLine}{Environment.NewLine}doesn't match pattern{Environment.NewLine}{patternLines[i]}{Environment.NewLine}Standard output:{Environment.NewLine}{testHostResult.StandardOutput}", - callerMemberName: callerMemberName, - callerFilePath: callerFilePath, - callerLineNumber: callerLineNumber); + $"Output on line {j + 1}{Environment.NewLine}{outputLine}{Environment.NewLine}doesn't match pattern{Environment.NewLine}{patternLines[i]}{Environment.NewLine}Standard output:{Environment.NewLine}{testHostResult.StandardOutput}{Environment.NewLine}for member '{callerMemberName}' at line {callerLineNumber} of file '{callerFilePath}'."); j++; } } public static void AssertOutputMatchesRegex(this TestHostResult testHostResult, [StringSyntax("Regex")] string pattern, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(Regex.IsMatch(testHostResult.StandardOutput, pattern), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => Assert.IsTrue(Regex.IsMatch(testHostResult.StandardOutput, pattern), GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); public static void AssertOutputMatchesRegex(this TestHostResult testHostResult, [StringSyntax("Regex")] string pattern, RegexOptions regexOptions, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(Regex.IsMatch(testHostResult.StandardOutput, pattern, regexOptions), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => Assert.IsTrue(Regex.IsMatch(testHostResult.StandardOutput, pattern, regexOptions), GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); public static void AssertOutputDoesNotMatchRegex(this TestHostResult testHostResult, [StringSyntax("Regex")] string pattern, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(!Regex.IsMatch(testHostResult.StandardOutput, pattern), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => Assert.IsFalse(Regex.IsMatch(testHostResult.StandardOutput, pattern), GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); public static void AssertOutputContains(this TestHostResult testHostResult, string value, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(testHostResult.StandardOutput.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => StringAssert.Contains(testHostResult.StandardOutput, value, GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber), StringComparison.Ordinal); public static void AssertOutputContains(this DotnetMuxerResult dotnetMuxerResult, string value, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(dotnetMuxerResult.StandardOutput.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(dotnetMuxerResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => StringAssert.Contains(dotnetMuxerResult.StandardOutput, value, GenerateFailedAssertionMessage(dotnetMuxerResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber), StringComparison.Ordinal); - public static void AssertOutputNotContains(this DotnetMuxerResult dotnetMuxerResult, string value, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(!dotnetMuxerResult.StandardOutput.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(dotnetMuxerResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + public static void AssertOutputDoesNotContain(this DotnetMuxerResult dotnetMuxerResult, string value, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) + => Assert.IsFalse(dotnetMuxerResult.StandardOutput.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(dotnetMuxerResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); - public static void AssertOutputRegEx(this DotnetMuxerResult dotnetMuxerResult, [StringSyntax("Regex")] string pattern, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(Regex.IsMatch(dotnetMuxerResult.StandardOutput, pattern), GenerateFailedAssertionMessage(dotnetMuxerResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + public static void AssertOutputMatchesRegex(this DotnetMuxerResult dotnetMuxerResult, [StringSyntax("Regex")] string pattern, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) + => Assert.IsTrue(Regex.IsMatch(dotnetMuxerResult.StandardOutput, pattern), GenerateFailedAssertionMessage(dotnetMuxerResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); public static void AssertOutputDoesNotContain(this TestHostResult testHostResult, string value, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(!testHostResult.StandardOutput.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => Assert.IsFalse(testHostResult.StandardOutput.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber)); public static void AssertStandardErrorContains(this TestHostResult testHostResult, string value, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) - => Assert.That(testHostResult.StandardError.Contains(value, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + => StringAssert.Contains(testHostResult.StandardError, value, GenerateFailedAssertionMessage(testHostResult, callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber), StringComparison.Ordinal); public static void AssertOutputContainsSummary(this TestHostResult testHostResult, int failed, int passed, int skipped, bool? aborted = false, int? minimumNumberOfTests = null, [CallerMemberName] string? callerMemberName = null, [CallerFilePath] string? callerFilePath = null, [CallerLineNumber] int callerLineNumber = 0) { @@ -136,13 +126,13 @@ public static void AssertOutputContainsSummary(this TestHostResult testHostResul succeeded: {passed} skipped: {skipped} """; - Assert.That(testHostResult.StandardOutput.Contains(summaryResult, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); - Assert.That(testHostResult.StandardOutput.Contains(summaryCounts, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult), callerMemberName: callerMemberName, callerFilePath: callerFilePath, callerLineNumber: callerLineNumber); + Assert.IsTrue(testHostResult.StandardOutput.Contains(summaryResult, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult, callerMemberName, callerFilePath, callerLineNumber)); + Assert.IsTrue(testHostResult.StandardOutput.Contains(summaryCounts, StringComparison.Ordinal), GenerateFailedAssertionMessage(testHostResult, callerMemberName, callerFilePath, callerLineNumber)); } - private static string GenerateFailedAssertionMessage(TestHostResult testHostResult) - => $"Output of the test host is:\n{testHostResult}"; + private static string GenerateFailedAssertionMessage(TestHostResult testHostResult, string? callerMemberName, string? callerFilePath, int callerLineNumber, [CallerMemberName] string? assertCallerMemberName = null) + => $"Expression '{assertCallerMemberName}' failed for member '{callerMemberName}' at line {callerLineNumber} of file '{callerFilePath}'. Output of the test host is:{Environment.NewLine}{testHostResult}"; - private static string GenerateFailedAssertionMessage(DotnetMuxerResult dotnetMuxerResult) - => $"Output of the dotnet muxer is:\n{dotnetMuxerResult}"; + private static string GenerateFailedAssertionMessage(DotnetMuxerResult dotnetMuxerResult, string? callerMemberName, string? callerFilePath, int callerLineNumber, [CallerMemberName] string? assertCallerMemberName = null) + => $"Expression '{assertCallerMemberName}' failed for member '{callerMemberName}' at line {callerLineNumber} of file '{callerFilePath}'. Output of the dotnet muxer is:{Environment.NewLine}{dotnetMuxerResult}"; } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceFixture.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceFixture.cs index 007fc22af7..1783ebe6a1 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceFixture.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceFixture.cs @@ -3,11 +3,16 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestFixture(TestFixtureSharingStrategy.PerTestApplication)] -public sealed class AcceptanceFixture : IDisposable +[TestClass] +public static class AcceptanceFixture { - public TempDirectory NuGetGlobalPackagesFolder { get; } = new(".packages"); + public static TempDirectory NuGetGlobalPackagesFolder { get; private set; } = null!; - public void Dispose() + [AssemblyInitialize] + public static void AssemblyInitialize(TestContext context) + => NuGetGlobalPackagesFolder = new(".packages"); + + [AssemblyCleanup] + public static void AssemblyCleanup() => NuGetGlobalPackagesFolder.Dispose(); } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceTestBase.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceTestBase.cs index 093d37d5b9..7c64902ec6 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceTestBase.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Helpers/AcceptanceTestBase.cs @@ -1,18 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; using System.Xml.Linq; namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -/// -/// All the properties of this class should be non static. -/// At the moment are static because we need to share them between perclass/id fixtures and -/// it's not supported at the moment. -/// -public abstract class AcceptanceTestBase : TestBase +public abstract class AcceptanceTestBase + where TFixture : ITestAssetFixture, new() { private const string NuGetPackageExtensionName = ".nupkg"; @@ -62,14 +59,10 @@ static AcceptanceTestBase() MSTestVersion = ExtractVersionFromPackage(Constants.ArtifactsPackagesShipping, "MSTest.TestFramework."); MicrosoftTestingPlatformVersion = ExtractVersionFromPackage(Constants.ArtifactsPackagesShipping, "Microsoft.Testing.Platform."); MicrosoftTestingEnterpriseExtensionsVersion = ExtractVersionFromXmlFile(versionsPropsFileDoc, "MicrosoftTestingExtensionsRetryVersion"); - MicrosoftTestingInternalFrameworkVersion = ExtractVersionFromXmlFile(directoryPackagesPropsFileDoc, "MicrosoftTestingInternalFrameworkVersion"); MSTestEngineVersion = ExtractVersionFromXmlFile(versionsPropsFileDoc, "MSTestEngineVersion"); } - protected AcceptanceTestBase(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } + protected static TFixture AssetFixture { get; private set; } = default!; internal static string RID { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) @@ -90,61 +83,70 @@ protected AcceptanceTestBase(ITestExecutionContext testExecutionContext) public static string MicrosoftTestingEnterpriseExtensionsVersion { get; private set; } - public static string MicrosoftTestingInternalFrameworkVersion { get; private set; } + [ClassInitialize(InheritanceBehavior.BeforeEachDerivedClass)] + [SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Fine in this context")] + public static async Task ClassInitialize(TestContext testContext) + { + AssetFixture = new(); + await AssetFixture.InitializeAsync(); + } + + [ClassCleanup(InheritanceBehavior.BeforeEachDerivedClass)] + [SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Fine in this context")] + public static void ClassCleanup() + => AssetFixture.Dispose(); - internal static IEnumerable> GetBuildMatrixTfmBuildVerbConfiguration() + internal static IEnumerable<(string Tfm, BuildConfiguration BuildConfiguration, Verb Verb)> GetBuildMatrixTfmBuildVerbConfiguration() { - foreach (TestArgumentsEntry tfm in TargetFrameworks.All) + foreach (string tfm in TargetFrameworks.All) { foreach (BuildConfiguration compilationMode in Enum.GetValues()) { foreach (Verb verb in Enum.GetValues()) { - yield return new TestArgumentsEntry<(string Tfm, BuildConfiguration BuildConfiguration, Verb Verb)>((tfm.Arguments, compilationMode, verb), $"{tfm.Arguments},{compilationMode},{verb}"); + yield return new(tfm, compilationMode, verb); } } } } - internal static IEnumerable> GetBuildMatrixTfmBuildConfiguration() + internal static IEnumerable<(string Tfm, BuildConfiguration BuildConfiguration)> GetBuildMatrixTfmBuildConfiguration() { - foreach (TestArgumentsEntry tfm in TargetFrameworks.All) + foreach (string tfm in TargetFrameworks.All) { foreach (BuildConfiguration compilationMode in Enum.GetValues()) { - yield return new TestArgumentsEntry<(string Tfm, BuildConfiguration BuildConfiguration)>((tfm.Arguments, compilationMode), $"{tfm.Arguments},{compilationMode}"); + yield return new(tfm, compilationMode); } } } - internal static IEnumerable> GetBuildMatrixMultiTfmFoldedBuildConfiguration() + internal static IEnumerable<(string MultiTfm, BuildConfiguration BuildConfiguration)> GetBuildMatrixMultiTfmFoldedBuildConfiguration() { foreach (BuildConfiguration compilationMode in Enum.GetValues()) { - yield return new TestArgumentsEntry<(string MultiTfm, BuildConfiguration BuildConfiguration)>((TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode), $"multitfm,{compilationMode}"); + yield return new(TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode); } } - internal static IEnumerable> GetBuildMatrixMultiTfmBuildConfiguration() + internal static IEnumerable<(string MultiTfm, BuildConfiguration BuildConfiguration)> GetBuildMatrixMultiTfmBuildConfiguration() { foreach (BuildConfiguration compilationMode in Enum.GetValues()) { - yield return new TestArgumentsEntry<(string MultiTfm, BuildConfiguration BuildConfiguration)>((TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode), $"{TargetFrameworks.All.ToMSBuildTargetFrameworks()},{compilationMode}"); + yield return new(TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode); } } - internal static IEnumerable> GetBuildMatrixSingleAndMultiTfmBuildConfiguration() + internal static IEnumerable<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm)> GetBuildMatrixSingleAndMultiTfmBuildConfiguration() { - foreach (TestArgumentsEntry<(string Tfm, BuildConfiguration BuildConfiguration)> entry in GetBuildMatrixTfmBuildConfiguration()) + foreach ((string Tfm, BuildConfiguration BuildConfiguration) entry in GetBuildMatrixTfmBuildConfiguration()) { - yield return new TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm)>( - (entry.Arguments.Tfm, entry.Arguments.BuildConfiguration, false), $"{entry.Arguments.Tfm},{entry.Arguments.BuildConfiguration}"); + yield return new(entry.Tfm, entry.BuildConfiguration, false); } - foreach (TestArgumentsEntry<(string MultiTfm, BuildConfiguration BuildConfiguration)> entry in GetBuildMatrixMultiTfmBuildConfiguration()) + foreach ((string MultiTfm, BuildConfiguration BuildConfiguration) entry in GetBuildMatrixMultiTfmBuildConfiguration()) { - yield return new TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm)>( - (entry.Arguments.MultiTfm, entry.Arguments.BuildConfiguration, true), $"multitfm,{entry.Arguments.BuildConfiguration}"); + yield return new(entry.MultiTfm, entry.BuildConfiguration, true); } } @@ -160,13 +162,13 @@ private static string ExtractVersionFromPackage(string rootFolder, string packag // So we need to find a package that contains a number after the prefix. // Ideally, we would want to do a full validation to check this is a nuget version number, but that's too much work for now. matches = matches - // (full path, file name without prefix) - .Select(path => (path, fileName: Path.GetFileName(path)[packagePrefixName.Length..])) - // check if first character of file name without prefix is number - .Where(tuple => int.TryParse(tuple.fileName[0].ToString(), CultureInfo.InvariantCulture, out _)) - // take the full path - .Select(tuple => tuple.path) - .ToArray(); + // (full path, file name without prefix) + .Select(path => (path, fileName: Path.GetFileName(path)[packagePrefixName.Length..])) + // check if first character of file name without prefix is number + .Where(tuple => int.TryParse(tuple.fileName[0].ToString(), CultureInfo.InvariantCulture, out _)) + // take the full path + .Select(tuple => tuple.path) + .ToArray(); } if (matches.Length != 1) diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/IgnoreExitCodeTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/IgnoreExitCodeTests.cs index b1b27a3e97..50bf5178bf 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/IgnoreExitCodeTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/IgnoreExitCodeTests.cs @@ -1,13 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class IgnoreExitCodeTests : AcceptanceTestBase +[TestClass] +public class IgnoreExitCodeTests : AcceptanceTestBase { private const string AssetName = "TestProject"; @@ -43,21 +40,21 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); @@ -83,21 +80,17 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context) } """; - private readonly AcceptanceFixture _acceptanceFixture; - - public IgnoreExitCodeTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - public static IEnumerable> GetBuildMatrix() + public static IEnumerable<(string Tfm, BuildConfiguration BuildConfiguration, string CommandLine, string EnvironmentVariable)> GetBuildMatrix() { - foreach (TestArgumentsEntry<(string Tfm, BuildConfiguration BuildConfiguration)> buildConfig in GetBuildMatrixTfmBuildConfiguration()) + foreach ((string Tfm, BuildConfiguration BuildConfiguration) buildConfig in GetBuildMatrixTfmBuildConfiguration()) { - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string)>((buildConfig.Arguments.Tfm, buildConfig.Arguments.BuildConfiguration, "--ignore-exit-code 2", string.Empty), $"{buildConfig.Arguments.Tfm},{buildConfig.Arguments.BuildConfiguration},CommandLine"); - yield return new TestArgumentsEntry<(string, BuildConfiguration, string, string)>((buildConfig.Arguments.Tfm, buildConfig.Arguments.BuildConfiguration, string.Empty, "2"), $"{buildConfig.Arguments.Tfm},{buildConfig.Arguments.BuildConfiguration},EnvironmentVariable"); + yield return new(buildConfig.Tfm, buildConfig.BuildConfiguration, "--ignore-exit-code 2", string.Empty); + yield return new(buildConfig.Tfm, buildConfig.BuildConfiguration, string.Empty, "2"); } } - [ArgumentsProvider(nameof(GetBuildMatrix))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method)] + [TestMethod] public async Task If_IgnoreExitCode_Specified_Should_Return_Success_ExitCode(string tfm, BuildConfiguration buildConfiguration, string commandLine, string environmentVariable) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -107,7 +100,7 @@ public async Task If_IgnoreExitCode_Specified_Should_Return_Success_ExitCode(str .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); string assetPath = generator.TargetAssetPath; - string globalPackagesPath = _acceptanceFixture.NuGetGlobalPackagesFolder.Path; + string globalPackagesPath = AcceptanceFixture.NuGetGlobalPackagesFolder.Path; await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {assetPath} -r {RID}", globalPackagesPath); await DotnetCli.RunAsync($"build -m:1 -nodeReuse:false {assetPath} -c {buildConfiguration} -r {RID}", globalPackagesPath); var host = TestInfrastructure.TestHost.LocateFrom(assetPath, AssetName, tfm, buildConfiguration: buildConfiguration); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs index 8ed4ecc05e..8ef8d9c03c 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs @@ -1,22 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; - using SL = Microsoft.Build.Logging.StructuredLogger; namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class MSBuildTests_KnownExtensionRegistration : AcceptanceTestBase +[TestClass] +public class MSBuildTests_KnownExtensionRegistration : AcceptanceTestBase { - private readonly AcceptanceFixture _acceptanceFixture; private const string AssetName = "MSBuildTests"; - public MSBuildTests_KnownExtensionRegistration(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task Microsoft_Testing_Platform_Extensions_ShouldBe_Correctly_Registered(string tfm, BuildConfiguration compilationMode, Verb verb) { TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -26,8 +21,8 @@ public async Task Microsoft_Testing_Platform_Extensions_ShouldBe_Correctly_Regis .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); - await DotnetCli.RunAsync($"restore -r {RID} {testAsset.TargetAssetPath}{Path.DirectorySeparatorChar}MSBuildTests.csproj", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); - await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"restore -r {RID} {testAsset.TargetAssetPath}{Path.DirectorySeparatorChar}MSBuildTests.csproj", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); var testHost = TestInfrastructure.TestHost.LocateFrom(testAsset.TargetAssetPath, AssetName, tfm, rid: RID, verb: verb, buildConfiguration: compilationMode); TestHostResult testHostResult = await testHost.ExecuteAsync("--help"); @@ -55,8 +50,8 @@ public async Task Microsoft_Testing_Platform_Extensions_ShouldBe_Correctly_Regis - DummyAdapter - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration + DummyTestFramework + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration @@ -93,17 +88,17 @@ public async Task Microsoft_Testing_Platform_Extensions_ShouldBe_Correctly_Regis namespace MyNamespaceRoot.Level1.Level2; -public static class DummyAdapterRegistration +public static class DummyTestFrameworkRegistration { public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, string[] args) { - testApplicationBuilder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter()); + testApplicationBuilder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyTestFramework()); } } -internal sealed class DummyAdapter : ITestFramework, IDataProducer +internal sealed class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => string.Empty; diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs index 8d3e9286c2..8040163b92 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs @@ -5,13 +5,11 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class MSBuildTests : AcceptanceTestBase +[TestClass] +public class MSBuildTests : AcceptanceTestBase { - public MSBuildTests(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string tfm, BuildConfiguration compilationMode, Verb verb) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -20,10 +18,9 @@ public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string .PatchCodeWithReplace("$TargetFrameworks$", tfm) .PatchCodeWithReplace("$JsonContent$", ConfigurationContent) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -v:normal -nodeReuse:false {testAsset.TargetAssetPath} -c {compilationMode}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -v:normal -nodeReuse:false {testAsset.TargetAssetPath} -c {compilationMode}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); var testHost = TestInfrastructure.TestHost.LocateFrom(testAsset.TargetAssetPath, "MSBuildTests", tfm, verb: verb, buildConfiguration: compilationMode); string generatedConfigurationFile = Path.Combine(testHost.DirectoryName, "MSBuildTests.testconfig.json"); @@ -31,7 +28,7 @@ public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string Assert.AreEqual(ConfigurationContent.Trim(), File.ReadAllText(generatedConfigurationFile).Trim()); Assert.IsTrue(compilationResult.StandardOutput.Contains("Microsoft Testing Platform configuration file written")); - compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -v:normal -nodeReuse:false {testAsset.TargetAssetPath} -c {compilationMode}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -v:normal -nodeReuse:false {testAsset.TargetAssetPath} -c {compilationMode}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); Assert.IsTrue(File.Exists(generatedConfigurationFile)); Assert.AreEqual(ConfigurationContent.Trim(), File.ReadAllText(generatedConfigurationFile).Trim()); compilationResult.StandardOutput.Contains("Microsoft Testing Platform configuration file written"); @@ -41,7 +38,7 @@ public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string \s*GenerateTestingPlatformConfigurationFile: \s*Skipping target "GenerateTestingPlatformConfigurationFile" because all output files are up\-to\-date with respect to the input files\. """)); - await DotnetCli.RunAsync($"clean -c {compilationMode} -v:normal {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"clean -c {compilationMode} -v:normal {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); // dotnet clean doesn't clean the publish output folder if (verb == Verb.build) @@ -50,7 +47,8 @@ public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string } } - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task ConfigFileGeneration_NoConfigurationFile_TaskWontRun(string tfm, BuildConfiguration compilationMode, Verb verb) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -59,12 +57,11 @@ public async Task ConfigFileGeneration_NoConfigurationFile_TaskWontRun(string tf .PatchCodeWithReplace("$TargetFrameworks$", tfm) .PatchCodeWithReplace("$JsonContent$", ConfigurationContent) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); File.Delete(Path.Combine(testAsset.TargetAssetPath, "testconfig.json")); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -v:diagnostic -nodeReuse:false {testAsset.TargetAssetPath} -c {compilationMode}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -v:diagnostic -nodeReuse:false {testAsset.TargetAssetPath} -c {compilationMode}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); var testHost = TestInfrastructure.TestHost.LocateFrom(testAsset.TargetAssetPath, "MSBuildTests", tfm, verb: verb, buildConfiguration: compilationMode); Assert.IsTrue(compilationResult.StandardOutput.Contains("Target \"GenerateTestingPlatformConfigurationFile\" skipped, due to false condition;")); @@ -94,11 +91,6 @@ public async Task ConfigFileGeneration_NoConfigurationFile_TaskWontRun(string tf - - - - - @@ -106,28 +98,45 @@ public async Task ConfigFileGeneration_NoConfigurationFile_TaskWontRun(string tf $JsonContent$ #file Program.cs -using MSBuildTests; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace MSBuildTests; +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Services; -[TestGroup] -public class UnitTest1 +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,__) => new DummyTestFramework()); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } } -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -"""; +public class DummyTestFramework : ITestFramework +{ + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); - private readonly AcceptanceFixture _acceptanceFixture; + public string Description => nameof(DummyTestFramework); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + public Task ExecuteRequestAsync(ExecuteRequestContext context) + { + context.Complete(); + return Task.CompletedTask; + } +} +"""; } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs index 8d1f11f367..9f87d0df98 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs @@ -1,23 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - using SL = Microsoft.Build.Logging.StructuredLogger; namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class MSBuildTests_EntryPoint : AcceptanceTestBase +[TestClass] +public class MSBuildTests_EntryPoint : AcceptanceTestBase { private const string AssetName = "MSBuildTests"; - private readonly AcceptanceFixture _acceptanceFixture; - - public MSBuildTests_EntryPoint(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task When_GenerateTestingPlatformEntryPoint_IsFalse_NoEntryPointInjected(string tfm, BuildConfiguration compilationMode, Verb verb) { using TestAsset testAsset = await TestAsset.GenerateAssetAsync( @@ -25,9 +19,9 @@ public async Task When_GenerateTestingPlatformEntryPoint_IsFalse_NoEntryPointInj CSharpSourceCode .PatchCodeWithReplace("$TargetFrameworks$", tfm) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"restore -r {RID} {testAsset.TargetAssetPath}{Path.DirectorySeparatorChar}MSBuildTests.csproj ", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"restore -r {RID} {testAsset.TargetAssetPath}{Path.DirectorySeparatorChar}MSBuildTests.csproj ", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); - compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -p:GenerateTestingPlatformEntryPoint=False -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", _acceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); + compilationResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -p:GenerateTestingPlatformEntryPoint=False -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); SL.Build binLog = SL.Serialization.Read(binlogFile); SL.Target generateTestingPlatformEntryPoint = binLog.FindChildrenRecursive().Single(t => t.Name == "_GenerateTestingPlatformEntryPoint"); Assert.AreEqual("Target \"_GenerateTestingPlatformEntryPoint\" skipped, due to false condition; ( '$(GenerateTestingPlatformEntryPoint)' == 'True' ) was evaluated as ( 'False' == 'True' ).", ((SL.Message)generateTestingPlatformEntryPoint.Children[0]).Text); @@ -38,7 +32,8 @@ public async Task When_GenerateTestingPlatformEntryPoint_IsFalse_NoEntryPointInj Assert.AreNotEqual(0, compilationResult.ExitCode); } - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task GenerateCSharpEntryPointAndVerifyTheCacheUsage(string tfm, BuildConfiguration compilationMode, Verb verb) => await GenerateAndVerifyLanguageSpecificEntryPoint(nameof(GenerateCSharpEntryPointAndVerifyTheCacheUsage), CSharpSourceCode, "cs", tfm, compilationMode, verb, @"Entrypoint source: @@ -62,7 +57,8 @@ internal sealed class TestingPlatformEntryPoint } }'", "Csc"); - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task GenerateVBEntryPointAndVerifyTheCacheUsage(string tfm, BuildConfiguration compilationMode, Verb verb) => await GenerateAndVerifyLanguageSpecificEntryPoint(nameof(GenerateVBEntryPointAndVerifyTheCacheUsage), VBSourceCode, "vb", tfm, compilationMode, verb, @"Entrypoint source: @@ -89,7 +85,8 @@ End Function End Module'", "Vbc"); - [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] + [TestMethod] public async Task GenerateFSharpEntryPointAndVerifyTheCacheUsage(string tfm, BuildConfiguration compilationMode, Verb verb) => await GenerateAndVerifyLanguageSpecificEntryPoint(nameof(GenerateFSharpEntryPointAndVerifyTheCacheUsage), FSharpSourceCode, "fs", tfm, compilationMode, verb, @"Entrypoint source: @@ -120,9 +117,9 @@ private async Task GenerateAndVerifyLanguageSpecificEntryPoint(string assetName, // We need to pickup local build packages -dev .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingPlatformVersion); using TestAsset testAsset = await TestAsset.GenerateAssetAsync(assetName, finalSourceCode); - await DotnetCli.RunAsync($"restore -r {RID} {testAsset.TargetAssetPath}{Path.DirectorySeparatorChar}MSBuildTests.{languageFileExtension}proj", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"restore -r {RID} {testAsset.TargetAssetPath}{Path.DirectorySeparatorChar}MSBuildTests.{languageFileExtension}proj", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); - DotnetMuxerResult buildResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult buildResult = await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); SL.Build binLog = SL.Serialization.Read(binlogFile); SL.Target generateTestingPlatformEntryPoint = binLog.FindChildrenRecursive().Single(t => t.Name == "_GenerateTestingPlatformEntryPoint"); SL.Task testingPlatformEntryPoint = generateTestingPlatformEntryPoint.FindChildrenRecursive().Single(t => t.Name == "TestingPlatformEntryPointTask"); @@ -141,7 +138,7 @@ private async Task GenerateAndVerifyLanguageSpecificEntryPoint(string assetName, Assert.IsNotNull(sourceFilePathInObj); File.Delete(binlogFile); - await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + await DotnetCli.RunAsync($"{(verb == Verb.publish ? $"publish -f {tfm}" : "build")} -c {compilationMode} -r {RID} -nodeReuse:false -bl:{binlogFile} {testAsset.TargetAssetPath} -v:n", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); binLog = SL.Serialization.Read(binlogFile); generateTestingPlatformEntryPoint = binLog.FindChildrenRecursive(t => t.Name == "_GenerateTestingPlatformEntryPoint" && t.Children.Count > 0).Single(); Assert.IsNotNull(generateTestingPlatformEntryPoint.FindChildrenRecursive(m => m.Text.Contains("Skipping target \"_GenerateTestingPlatformEntryPoint\" because all output files are up-to-date with respect to the input files.", StringComparison.OrdinalIgnoreCase)).Single()); @@ -158,15 +155,15 @@ private async Task GenerateAndVerifyLanguageSpecificEntryPoint(string assetName, - DummyAdapter - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration + DummyTestFramework + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration - DummyAdapter2 - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration2 + DummyTestFramework2 + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration2 @@ -181,7 +178,6 @@ private async Task GenerateAndVerifyLanguageSpecificEntryPoint(string assetName, - @@ -195,15 +191,15 @@ private async Task GenerateAndVerifyLanguageSpecificEntryPoint(string assetName, namespace MyNamespaceRoot.Level1.Level2; -public static class DummyAdapterRegistration +public static class DummyTestFrameworkRegistration { public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, string[] args) { - testApplicationBuilder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyAdapter()); + testApplicationBuilder.RegisterTestFramework(_ => new Capabilities(), (_, __) => new DummyTestFramework()); } } -public static class DummyAdapterRegistration2 +public static class DummyTestFrameworkRegistration2 { public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, string[] args) { @@ -211,9 +207,9 @@ public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, } } -internal sealed class DummyAdapter : ITestFramework, IDataProducer +internal sealed class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => string.Empty; @@ -249,15 +245,15 @@ internal sealed class Capabilities : ITestFrameworkCapabilities - DummyAdapter - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration + DummyTestFramework + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration - DummyAdapter2 - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration2 + DummyTestFramework2 + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration2 @@ -269,7 +265,6 @@ internal sealed class Capabilities : ITestFrameworkCapabilities - @@ -284,18 +279,18 @@ Imports Microsoft.Testing.Platform.Extensions Imports Microsoft.Testing.Platform Namespace MyNamespaceRoot.Level1.Level2 - Public Module DummyAdapterRegistration + Public Module DummyTestFrameworkRegistration Public Sub AddExtensions(builder As ITestApplicationBuilder, args As String()) - builder.RegisterTestFramework(Function() New Capabilities(), Function(cap, services) New DummyAdapter()) + builder.RegisterTestFramework(Function() New Capabilities(), Function(cap, services) New DummyTestFramework()) End Sub End Module - Public Module DummyAdapterRegistration2 + Public Module DummyTestFrameworkRegistration2 Public Sub AddExtensions(builder As ITestApplicationBuilder, args As String()) End Sub End Module - Class DummyAdapter + Class DummyTestFramework Implements ITestFramework Implements IDataProducer @@ -375,15 +370,15 @@ End Namespace - DummyAdapter - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration + DummyTestFramework + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration - DummyAdapter2 - MyNamespaceRoot.Level1.Level2.DummyAdapterRegistration2 + DummyTestFramework2 + MyNamespaceRoot.Level1.Level2.DummyTestFrameworkRegistration2 @@ -419,11 +414,11 @@ type Capabilities () = interface ITestFrameworkCapabilities with member _.Capabilities = [||] -type DummyAdapter() = +type DummyTestFramework() = let dataProducer = { new IDataProducer with member _.DataTypesProduced = [| typedefof |] - member _.Uid = nameof(DummyAdapter) + member _.Uid = nameof(DummyTestFramework) member _.Version = "" member _.DisplayName = "" member _.Description = "" @@ -432,7 +427,7 @@ member _.IsEnabledAsync() = Task.FromResult true } interface ITestFramework with - member _.Uid = nameof(DummyAdapter) + member _.Uid = nameof(DummyTestFramework) member _.Version = "" member _.DisplayName = "" member _.Description = "" @@ -449,11 +444,11 @@ member _.IsEnabledAsync() = Task.FromResult true context.Complete() } -module DummyAdapterRegistration = +module DummyTestFrameworkRegistration = let AddExtensions (testApplicationBuilder : ITestApplicationBuilder, args: string[]) = - testApplicationBuilder.RegisterTestFramework((fun _ -> Capabilities()), (fun _ _ -> DummyAdapter())) |> ignore + testApplicationBuilder.RegisterTestFramework((fun _ -> Capabilities()), (fun _ _ -> DummyTestFramework())) |> ignore -module DummyAdapterRegistration2 = +module DummyTestFrameworkRegistration2 = let AddExtensions (_, _) = () """; diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs index 60043750e6..936bc59983 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs @@ -1,22 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class MSBuildTests_Solution : AcceptanceTestBase +[TestClass] +public class MSBuildTests_Solution : AcceptanceTestBase { - private readonly AcceptanceFixture _acceptanceFixture; private const string AssetName = "MSTestProject"; - public MSBuildTests_Solution(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - - internal static IEnumerable> GetBuildMatrix() + internal static IEnumerable<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm, string Command)> GetBuildMatrix() { - foreach (TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm)> entry in GetBuildMatrixSingleAndMultiTfmBuildConfiguration()) + foreach ((string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm) entry in GetBuildMatrixSingleAndMultiTfmBuildConfiguration()) { foreach (string command in new string[] { @@ -24,13 +18,13 @@ public MSBuildTests_Solution(ITestExecutionContext testExecutionContext, Accepta "test --no-restore", }) { - yield return new TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm, string Command)>( - (entry.Arguments.SingleTfmOrMultiTfm, entry.Arguments.BuildConfiguration, entry.Arguments.IsMultiTfm, command), $"{(entry.Arguments.IsMultiTfm ? "multitfm" : entry.Arguments.SingleTfmOrMultiTfm)},{entry.Arguments.BuildConfiguration},{command}"); + yield return new(entry.SingleTfmOrMultiTfm, entry.BuildConfiguration, entry.IsMultiTfm, command); } } } - [ArgumentsProvider(nameof(GetBuildMatrix))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method)] + [TestMethod] public async Task MSBuildTests_UseMSBuildTestInfrastructure_Should_Run_Solution_Tests(string singleTfmOrMultiTfm, BuildConfiguration _, bool isMultiTfm, string command) { using TestAsset generator = await TestAsset.GenerateAssetAsync( @@ -38,13 +32,10 @@ public async Task MSBuildTests_UseMSBuildTestInfrastructure_Should_Run_Solution_ SourceCode .PatchCodeWithReplace("$TargetFrameworks$", isMultiTfm ? $"{singleTfmOrMultiTfm}" : $"{singleTfmOrMultiTfm}") .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); string projectContent = File.ReadAllText(Directory.GetFiles(generator.TargetAssetPath, "MSBuildTests.csproj", SearchOption.AllDirectories).Single()); string programSourceContent = File.ReadAllText(Directory.GetFiles(generator.TargetAssetPath, "Program.cs", SearchOption.AllDirectories).Single()); - string unitTestSourceContent = File.ReadAllText(Directory.GetFiles(generator.TargetAssetPath, "UnitTest1.cs", SearchOption.AllDirectories).Single()); - string usingsSourceContent = File.ReadAllText(Directory.GetFiles(generator.TargetAssetPath, "Usings.cs", SearchOption.AllDirectories).Single()); string nugetConfigContent = File.ReadAllText(Directory.GetFiles(generator.TargetAssetPath, "NuGet.config", SearchOption.AllDirectories).Single()); // Create a solution with 3 projects @@ -57,32 +48,30 @@ public async Task MSBuildTests_UseMSBuildTestInfrastructure_Should_Run_Solution_ CSharpProject project = solution.CreateCSharpProject($"TestProject{i}", isMultiTfm ? singleTfmOrMultiTfm.Split(';') : [singleTfmOrMultiTfm]); File.WriteAllText(project.ProjectFile, projectContent); project.AddOrUpdateFileContent("Program.cs", programSourceContent.PatchCodeWithReplace("$ProjectName$", $"TestProject{i}")); - project.AddOrUpdateFileContent("UnitTest1.cs", unitTestSourceContent); - project.AddOrUpdateFileContent("Usings.cs", usingsSourceContent); CSharpProject project2 = solution.CreateCSharpProject($"Project{i}", isMultiTfm ? singleTfmOrMultiTfm.Split(';') : [singleTfmOrMultiTfm]); project.AddProjectReference(project2.ProjectFile); } // Build the solution - DotnetMuxerResult restoreResult = await DotnetCli.RunAsync($"restore -nodeReuse:false {solution.SolutionFile} --configfile {nugetFile}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); - restoreResult.AssertOutputNotContains("An approximate best match of"); - DotnetMuxerResult testResult = await DotnetCli.RunAsync($"{command} -nodeReuse:false {solution.SolutionFile}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + DotnetMuxerResult restoreResult = await DotnetCli.RunAsync($"restore -nodeReuse:false {solution.SolutionFile} --configfile {nugetFile}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); + restoreResult.AssertOutputDoesNotContain("An approximate best match of"); + DotnetMuxerResult testResult = await DotnetCli.RunAsync($"{command} -nodeReuse:false {solution.SolutionFile}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path); if (isMultiTfm) { foreach (string tfm in singleTfmOrMultiTfm.Split(';')) { - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject0\..*' \[{tfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject1\..*' \[{tfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject2\..*' \[{tfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject0\..*' \[{tfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject1\..*' \[{tfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject2\..*' \[{tfm}\|x64\]"); } } else { - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject0\..*' \[{singleTfmOrMultiTfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject1\..*' \[{singleTfmOrMultiTfm}\|x64\]"); - testResult.AssertOutputRegEx($@"Tests succeeded: '.*TestProject2\..*' \[{singleTfmOrMultiTfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject0\..*' \[{singleTfmOrMultiTfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject1\..*' \[{singleTfmOrMultiTfm}\|x64\]"); + testResult.AssertOutputMatchesRegex($@"Tests succeeded: '.*TestProject2\..*' \[{singleTfmOrMultiTfm}\|x64\]"); } } @@ -102,38 +91,61 @@ public async Task MSBuildTests_UseMSBuildTestInfrastructure_Should_Run_Solution_ - - - - #file Program.cs -using MSBuildTests; -using $ProjectName$; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -builder.AddMSBuild(); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace MSBuildTests; - -[TestGroup] -public class UnitTest1 +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.MSBuild; +using Microsoft.Testing.Platform.Services; + +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,__) => new DummyTestFramework()); + builder.AddMSBuild(); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } } -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Platform.MSBuild; +public class DummyTestFramework : ITestFramework, IDataProducer +{ + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); + + public string Description => nameof(DummyTestFramework); + + public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)]; + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + + public async Task ExecuteRequestAsync(ExecuteRequestContext context) + { + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "1", DisplayName = "Test1", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "1", DisplayName = "Test1", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); + + context.Complete(); + } +} """; } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs index d057c61852..796bcfffe2 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs @@ -1,45 +1,27 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Reflection; using System.Runtime.InteropServices; using System.Text.RegularExpressions; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class MSBuildTests_Test : AcceptanceTestBase +[TestClass] +public class MSBuildTests_Test : AcceptanceTestBase { private const string AssetName = "MSBuildTests"; - private readonly AcceptanceFixture _acceptanceFixture; - - public MSBuildTests_Test(ITestExecutionContext testExecutionContext, AcceptanceFixture acceptanceFixture) - : base(testExecutionContext) => _acceptanceFixture = acceptanceFixture; - internal static TestArgumentsEntry<(string BuildCommand, string TargetFramework, BuildConfiguration BuildConfiguration, bool TestSucceeded)> FormatBuildMatrixEntry(TestArgumentsContext ctx) - { - var entry = ((string, string, BuildConfiguration, bool))ctx.Arguments; - return new TestArgumentsEntry<(string, string, BuildConfiguration, bool)>(entry, $"{entry.Item1},{(TargetFrameworks.All.ToMSBuildTargetFrameworks() == entry.Item2 ? "multitfm" : entry.Item2)},{entry.Item3},{(entry.Item4 ? "Succeeded" : "Failed")}"); - } + public static string? FormatBuildMatrixEntry(MethodInfo method, object?[]? data) + => $"{data![0]},{(string.Equals(TargetFrameworks.All.ToMSBuildTargetFrameworks(), data[1]) ? "multitfm" : data[1])},{data[2]},{((bool)data[3]! ? "Succeeded" : "Failed")}"; internal static IEnumerable<(string BuildCommand, string TargetFramework, BuildConfiguration BuildConfiguration, bool TestSucceeded)> GetBuildMatrix() { - foreach (TestArgumentsEntry tfm in TargetFrameworks.All) + foreach (string tfm in TargetFrameworks.All) { - foreach (BuildConfiguration compilationMode in Enum.GetValues()) + foreach ((string buildCommand, _, BuildConfiguration buildConfiguration, bool testSucceeded) in GetBuildMatrixMultiTfm()) { - foreach (bool testSucceeded in new bool[] { true, false }) - { - foreach (string buildCommand in new string[] - { - "build -t:Test", - "test -p:TestingPlatformDotnetTestSupport=True", - }) - { - yield return (buildCommand, tfm.Arguments, compilationMode, testSucceeded); - } - } + yield return (buildCommand, tfm, buildConfiguration, testSucceeded); } } } @@ -50,25 +32,21 @@ public MSBuildTests_Test(ITestExecutionContext testExecutionContext, AcceptanceF { foreach (bool testSucceeded in new bool[] { true, false }) { - foreach (string buildCommand in new string[] - { - "build -t:Test", - "test -p:TestingPlatformDotnetTestSupport=True", - }) - { - yield return (buildCommand, TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode, testSucceeded); - } + yield return ("build -t:Test", TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode, testSucceeded); + yield return ("test -p:TestingPlatformDotnetTestSupport=True", TargetFrameworks.All.ToMSBuildTargetFrameworks(), compilationMode, testSucceeded); } } } - [ArgumentsProvider(nameof(GetBuildMatrix), TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] + [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail_SingleTfm(string testCommand, string tfm, BuildConfiguration compilationMode, bool testSucceeded) => await InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(testCommand, tfm, false, [tfm], compilationMode, testSucceeded); - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfm), TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrixMultiTfm), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] + [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail_MultiTfm(string testCommand, string multiTfm, BuildConfiguration compilationMode, bool testSucceeded) - => await InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(testCommand, multiTfm, true, TargetFrameworks.All.Select(x => x.Arguments).ToArray(), compilationMode, testSucceeded); + => await InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(testCommand, multiTfm, true, TargetFrameworks.All, compilationMode, testSucceeded); private async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(string testCommand, string tfm, bool isMultiTfm, string[] tfmsToAssert, BuildConfiguration compilationMode, bool testSucceeded) { @@ -78,12 +56,10 @@ private async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Sho .PatchCodeWithReplace("$PlatformTarget$", "x64") .PatchCodeWithReplace("$TargetFrameworks$", isMultiTfm ? $"{tfm}" : $"{tfm}") .PatchCodeWithReplace("$AssertValue$", testSucceeded.ToString().ToLowerInvariant()) - .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); string testResultFolder = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N")); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{testCommand} -p:TestingPlatformCommandLineArguments=\"--results-directory %22{testResultFolder}%22\" -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\"", _acceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{testCommand} -p:TestingPlatformCommandLineArguments=\"--results-directory %22{testResultFolder}%22\" -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\"", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); foreach (string tfmToAssert in tfmsToAssert) { @@ -91,13 +67,15 @@ private async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Sho } } - [ArgumentsProvider(nameof(GetBuildMatrix), TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] + [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_SingleTfm(string testCommand, string tfm, BuildConfiguration compilationMode, bool testSucceeded) => await InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_Detail(testCommand, tfm, false, [tfm], compilationMode, testSucceeded); - [ArgumentsProvider(nameof(GetBuildMatrixMultiTfm), TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrixMultiTfm), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] + [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_MultiTfm(string testCommand, string multiTfm, BuildConfiguration compilationMode, bool testSucceeded) - => await InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_Detail(testCommand, multiTfm, true, TargetFrameworks.All.Select(x => x.Arguments).ToArray(), compilationMode, testSucceeded); + => await InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_Detail(testCommand, multiTfm, true, TargetFrameworks.All, compilationMode, testSucceeded); private async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_Detail(string testCommand, string tfm, bool isMultiTfm, string[] tfmsToAssert, BuildConfiguration compilationMode, bool testSucceeded) { @@ -107,19 +85,17 @@ private async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_An .PatchCodeWithReplace("$PlatformTarget$", "x64") .PatchCodeWithReplace("$TargetFrameworks$", isMultiTfm ? $"{tfm}" : $"{tfm}") .PatchCodeWithReplace("$AssertValue$", testSucceeded.ToString().ToLowerInvariant()) - .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); string testResultFolder = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N")); DotnetMuxerResult compilationResult = testCommand.StartsWith("test", StringComparison.OrdinalIgnoreCase) ? await DotnetCli.RunAsync( - $"{testCommand} -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\" -- --treenode-filter /*/*/*/TestMethod1 --results-directory \"{testResultFolder}\"", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path) + $"{testCommand} -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\" -- --treenode-filter --results-directory \"{testResultFolder}\"", + AcceptanceFixture.NuGetGlobalPackagesFolder.Path) : await DotnetCli.RunAsync( - $"{testCommand} -p:TestingPlatformCommandLineArguments=\"--treenode-filter /*/*/*/TestMethod1 --results-directory \"{testResultFolder}\"\" -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\"", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + $"{testCommand} -p:TestingPlatformCommandLineArguments=\"--treenode-filter --results-directory \"{testResultFolder}\"\" -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\"", + AcceptanceFixture.NuGetGlobalPackagesFolder.Path); foreach (string tfmToAssert in tfmsToAssert) { @@ -127,6 +103,7 @@ private async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_An } } + [TestMethod] public async Task Invoke_DotnetTest_With_Arch_Switch_x86_Should_Work() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -145,15 +122,13 @@ public async Task Invoke_DotnetTest_With_Arch_Switch_x86_Should_Work() AssetName, SourceCode .PatchCodeWithReplace("$PlatformTarget$", string.Empty) - .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent.Arguments}") + .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent}") .PatchCodeWithReplace("$AssertValue$", bool.TrueString.ToLowerInvariant()) - .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); await DotnetCli.RunAsync( $"test --arch x86 -p:TestingPlatformDotnetTestSupport=True -p:Configuration=Release -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\"", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, environmentVariables: dotnetRootX86, failIfReturnValueIsNotZero: false); @@ -164,6 +139,7 @@ await DotnetCli.RunAsync( Assert.IsTrue(Regex.IsMatch(logFileContent, @"\.dotnet\\x86\\dotnet\.exe"), logFileContent); } + [TestMethod] public async Task Invoke_DotnetTest_With_Incompatible_Arch() { Architecture currentArchitecture = RuntimeInformation.ProcessArchitecture; @@ -177,14 +153,12 @@ public async Task Invoke_DotnetTest_With_Incompatible_Arch() AssetName, SourceCode .PatchCodeWithReplace("$PlatformTarget$", string.Empty) - .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent.Arguments}") + .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent}") .PatchCodeWithReplace("$AssertValue$", bool.TrueString.ToLowerInvariant()) - .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); DotnetMuxerResult result = await DotnetCli.RunAsync( $"test --arch {incompatibleArchitecture} -p:TestingPlatformDotnetTestSupport=True \"{testAsset.TargetAssetPath}\"", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); // The output looks like: /* @@ -202,6 +176,7 @@ public async Task Invoke_DotnetTest_With_Incompatible_Arch() result.AssertOutputContains(" - https://aka.ms/dotnet-download"); } + [TestMethod] public async Task Invoke_DotnetTest_With_DOTNET_HOST_PATH_Should_Work() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -220,15 +195,13 @@ public async Task Invoke_DotnetTest_With_DOTNET_HOST_PATH_Should_Work() AssetName, SourceCode .PatchCodeWithReplace("$PlatformTarget$", string.Empty) - .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent.Arguments}") + .PatchCodeWithReplace("$TargetFrameworks$", $"{TargetFrameworks.NetCurrent}") .PatchCodeWithReplace("$AssertValue$", bool.TrueString.ToLowerInvariant()) - .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); await DotnetCli.RunAsync( $"test -p:TestingPlatformDotnetTestSupport=True -p:Configuration=Release -p:nodeReuse=false -bl:{binlogFile} \"{testAsset.TargetAssetPath}\"", - _acceptanceFixture.NuGetGlobalPackagesFolder.Path, + AcceptanceFixture.NuGetGlobalPackagesFolder.Path, environmentVariables: dotnetHostPathEnvVar, failIfReturnValueIsNotZero: false); @@ -255,9 +228,11 @@ private static void CommonAssert(DotnetMuxerResult compilationResult, string tfm Assert.IsFalse(string.IsNullOrEmpty(File.ReadAllText(outputFileLog)), $"Content of file '{File.ReadAllText(outputFileLog)}'"); } - // We avoid to test the multi-tfm because it's already tested with the above tests and we don't want to have too heavy testing, msbuild is pretty heavy (a lot of processes started due to the no 'nodereuse') and makes tests flaky. + // We avoid to test the multi-tfm because it's already tested with the above tests and we don't want to have too heavy testing, + // msbuild is pretty heavy (a lot of processes started due to the no 'nodereuse') and makes tests flaky. // We test two functionality for the same reason, we don't want to load too much the CI only for UX reasons. - [ArgumentsProvider(nameof(GetBuildMatrix), TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] + [TestMethod] public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_The_Output_SingleTfm(string testCommand, string tfm, BuildConfiguration compilationMode, bool testSucceeded) { // We test only failed but we don't want to have too much argument provider overload. @@ -272,14 +247,13 @@ public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_ .PatchCodeWithReplace("$PlatformTarget$", "x64") .PatchCodeWithReplace("$TargetFrameworks$", $"{tfm}") .PatchCodeWithReplace("$AssertValue$", testSucceeded.ToString().ToLowerInvariant()) - .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion)); string binlogFile = Path.Combine(testAsset.TargetAssetPath, Guid.NewGuid().ToString("N"), "msbuild.binlog"); - DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{testCommand} -p:TestingPlatformShowTestsFailure=True -p:TestingPlatformCaptureOutput=False -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} {testAsset.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); - Assert.Contains("error test failed: TestMethod2 (", compilationResult.StandardOutput); - Assert.Contains("Assert.IsTrue: Expected 'true', but got 'false'.", compilationResult.StandardOutput); - Assert.Contains(".NET Testing Platform", compilationResult.StandardOutput); + DotnetMuxerResult compilationResult = await DotnetCli.RunAsync($"{testCommand} -p:TestingPlatformShowTestsFailure=True -p:TestingPlatformCaptureOutput=False -p:Configuration={compilationMode} -p:nodeReuse=false -bl:{binlogFile} {testAsset.TargetAssetPath}", AcceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false); + + compilationResult.AssertOutputContains("error test failed: Test2 ("); + compilationResult.AssertOutputContains("FAILED: Expected 'true', but got 'false'."); + compilationResult.AssertOutputContains(".NET Testing Platform"); } private const string SourceCode = """ @@ -298,42 +272,93 @@ public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_ - - - - #file Program.cs -using MSBuildTests; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new MSBuild_Tests.SourceGeneratedTestNodesBuilder()); -builder.AddMSBuild(); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace MSBuildTests; - -[TestGroup] -public class UnitTest1 +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions; +using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Helpers; +using Microsoft.Testing.Platform.MSBuild; +using Microsoft.Testing.Platform.Services; + +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + MyExtension myExtension = new(); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,sp) => new DummyTestFramework(sp, myExtension)); + builder.AddTreeNodeFilterService(myExtension); + builder.AddMSBuild(); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } +} - public void TestMethod2() +public class MyExtension : IExtension +{ + public string Uid => "MyExtension"; + public string Version => "1.0.0"; + public string DisplayName => "My Extension"; + public string Description => "My Extension Description"; + public Task IsEnabledAsync() => Task.FromResult(true); +} + +public class DummyTestFramework : ITestFramework, IDataProducer +{ + private IServiceProvider _sp; + private MyExtension _myExtension; + + public DummyTestFramework(IServiceProvider sp, MyExtension myExtension) { - Assert.IsTrue($AssertValue$); + _sp = sp; + _myExtension = myExtension; } -} -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Platform.MSBuild; + public string Uid => _myExtension.Uid; + + public string Version => _myExtension.Version; + + public string DisplayName => _myExtension.DisplayName; + + public string Description => _myExtension.Description; + + public Type[] DataTypesProduced => [typeof(TestNodeUpdateMessage)]; + + public Task IsEnabledAsync() => _myExtension.IsEnabledAsync(); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + + public async Task ExecuteRequestAsync(ExecuteRequestContext context) + { + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode { Uid = "1", DisplayName = "Test1", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode { Uid = "1", DisplayName = "Test1", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); + + if (!_sp.GetCommandLineOptions().TryGetOptionArgumentList("--treenode-filter", out _)) + { + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode { Uid = "2", DisplayName = "Test2", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode { Uid = "2", DisplayName = "Test2", Properties = new($AssertValue$ ? PassedTestNodeStateProperty.CachedInstance : new FailedTestNodeStateProperty("FAILED: Expected 'true', but got 'false'.")) })); + } + + context.Complete(); + } +} """; } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs index 7456dea256..44ebf81d34 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MaxFailedTestsExtensionTests.cs @@ -1,23 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class MaxFailedTestsExtensionTests : AcceptanceTestBase +[TestClass] +public class MaxFailedTestsExtensionTests : AcceptanceTestBase { private const string AssetName = nameof(MaxFailedTestsExtensionTests); - private readonly TestAssetFixture _testAssetFixture; - - public MaxFailedTestsExtensionTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; + [TestMethod] public async Task TestMaxFailedTestsShouldCallStopTestExecutionAsync() { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--maximum-failed-tests 2"); testHostResult.AssertExitCodeIs(ExitCodes.TestExecutionStoppedForMaxFailedTests); @@ -26,9 +20,10 @@ public async Task TestMaxFailedTestsShouldCallStopTestExecutionAsync() testHostResult.AssertOutputContainsSummary(failed: 3, passed: 3, skipped: 0); } + [TestMethod] public async Task WhenCapabilityIsMissingShouldFail() { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetCurrent.Arguments); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, TargetFrameworks.NetCurrent); TestHostResult testHostResult = await testHost.ExecuteAsync("--maximum-failed-tests 2", environmentVariables: new() { ["DO_NOT_ADD_CAPABILITY"] = "1", @@ -38,8 +33,7 @@ public async Task WhenCapabilityIsMissingShouldFail() testHostResult.AssertOutputContains("The current test framework does not implement 'IGracefulStopTestExecutionCapability' which is required for '--maximum-failed-tests' feature."); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string Sources = """ #file MaxFailedTestsExtensionTests.csproj @@ -74,11 +68,11 @@ internal sealed class Program public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - var adapter = new DummyAdapter(); - builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => adapter); + var testFramework = new DummyTestFramework(); + builder.RegisterTestFramework(_ => new Capabilities(), (_, __) => testFramework); #pragma warning disable TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. - builder.AddMaximumFailedTestsService(adapter); + builder.AddMaximumFailedTestsService(testFramework); #pragma warning restore TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. using ITestApplication app = await builder.BuildAsync(); @@ -86,9 +80,9 @@ public static async Task Main(string[] args) } } -internal class DummyAdapter : ITestFramework, IDataProducer +internal class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => string.Empty; diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj index 45b3af34c2..8e13bcf2f9 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj @@ -4,9 +4,9 @@ $(NetCurrent) $(TestRunnerAdditionalArguments) --retry-failed-tests 3 false + true $(DefineConstants);SKIP_INTERMEDIATE_TARGET_FRAMEWORKS Exe - true @@ -24,21 +24,15 @@ - + + + - - - - - - - - diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/NoBannerTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/NoBannerTests.cs index 599edb8d81..9e7308c844 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/NoBannerTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/NoBannerTests.cs @@ -1,35 +1,30 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class NoBannerTests : AcceptanceTestBase +[TestClass] +public class NoBannerTests : AcceptanceTestBase { private const string AssetName = "NoBannerTest"; - private readonly TestAssetFixture _testAssetFixture; private readonly string _bannerRegexMatchPattern = @".NET Testing Platform v.+ \[.+\]"; - public NoBannerTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task UsingNoBanner_TheBannerDoesNotAppear(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--no-banner"); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); testHostResult.AssertOutputDoesNotMatchRegex(_bannerRegexMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task UsingNoBanner_InTheEnvironmentVars_TheBannerDoesNotAppear(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -41,10 +36,11 @@ public async Task UsingNoBanner_InTheEnvironmentVars_TheBannerDoesNotAppear(stri testHostResult.AssertOutputDoesNotMatchRegex(_bannerRegexMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task UsingDotnetNoLogo_InTheEnvironmentVars_TheBannerDoesNotAppear(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( null, new Dictionary @@ -56,18 +52,18 @@ public async Task UsingDotnetNoLogo_InTheEnvironmentVars_TheBannerDoesNotAppear( testHostResult.AssertOutputDoesNotMatchRegex(_bannerRegexMatchPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task WithoutUsingNoBanner_TheBannerAppears(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); testHostResult.AssertOutputMatchesRegex(_bannerRegexMatchPattern); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string NoBannerTestCode = """ #file NoBannerTest.csproj @@ -96,21 +92,21 @@ public class Program public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework +public class DummyTestFramework : ITestFramework { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Program.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Program.cs index f78a15125c..4514fbbfd0 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Program.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Program.cs @@ -2,10 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Diagnostics; +using System.Reflection; using Microsoft.Testing.Extensions; -using Microsoft.Testing.Internal.Framework.Configurations; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] // Opt-out telemetry Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1"); @@ -15,7 +17,7 @@ ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new TestFrameworkConfiguration(Debugger.IsAttached ? 1 : Environment.ProcessorCount), new SourceGeneratedTestNodesBuilder()); +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); #endif diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Properties/launchSettings.json b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Properties/launchSettings.json index 2610486891..aefd9415fa 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Properties/launchSettings.json +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Microsoft.Testing.Platform.Acceptance.IntegrationTests": { "commandName": "Project", - "commandLineArgs": "--treenode-filter /*/*/*/**", + "commandLineArgs": "", "environmentVariables": { //"TESTINGPLATFORM_HOTRELOAD_ENABLED": "1" } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ServerLoggingTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ServerLoggingTests.cs index fc136a2958..3215b5ad54 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ServerLoggingTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ServerLoggingTests.cs @@ -9,19 +9,15 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed partial class ServerLoggingTests : ServerModeTestsBase +[TestClass] +public sealed partial class ServerLoggingTests : ServerModeTestsBase { - private readonly TestAssetFixture _testAssetFixture; - - public ServerLoggingTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - + [TestMethod] public async Task RunningInServerJsonRpcModeShouldHaveOutputDeviceLogsPushedToTestExplorer() { - string tfm = TargetFrameworks.NetCurrent.Arguments; - string resultDirectory = Path.Combine(_testAssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "ServerLoggingTests", tfm); + string tfm = TargetFrameworks.NetCurrent; + string resultDirectory = Path.Combine(AssetFixture.TargetAssetPath, Guid.NewGuid().ToString("N"), tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "ServerLoggingTests", tfm); using TestingPlatformClient jsonClient = await StartAsServerAndConnectToTheClientAsync(testHost); LogsCollector logs = new(); jsonClient.RegisterLogListener(logs); @@ -43,27 +39,26 @@ public async Task RunningInServerJsonRpcModeShouldHaveOutputDeviceLogsPushedToTe Assert.AreEqual( $$""" Log { LogLevel = Information, Message = Connecting to client host '127.0.0.1' port '{{port}}' } - Log { LogLevel = Trace, Message = Starting test session. Log file path is '{{logPath}}'. } + Log { LogLevel = Trace, Message = Starting test session. The log file path is '{{logPath}}'. } Log { LogLevel = Error, Message = System.Exception: This is an exception output } - Log { LogLevel = Error, Message = This is a red output with padding set to 3 } - Log { LogLevel = Warning, Message = This is a yellow output with padding set to 2 } + Log { LogLevel = Information, Message = This is a red output with padding set to 3 } + Log { LogLevel = Information, Message = This is a yellow output with padding set to 2 } Log { LogLevel = Information, Message = This is a blue output with padding set to 1 } Log { LogLevel = Information, Message = This is normal text output. } - Log { LogLevel = Trace, Message = Finished test session } - Log { LogLevel = Trace, Message = Starting test session. Log file path is '{{logPath}}'. } + Log { LogLevel = Trace, Message = Finished test session. } + Log { LogLevel = Trace, Message = Starting test session. The log file path is '{{logPath}}'. } Log { LogLevel = Error, Message = System.Exception: This is an exception output } - Log { LogLevel = Error, Message = This is a red output with padding set to 3 } - Log { LogLevel = Warning, Message = This is a yellow output with padding set to 2 } + Log { LogLevel = Information, Message = This is a red output with padding set to 3 } + Log { LogLevel = Information, Message = This is a yellow output with padding set to 2 } Log { LogLevel = Information, Message = This is a blue output with padding set to 1 } Log { LogLevel = Information, Message = This is normal text output. } - Log { LogLevel = Trace, Message = Finished test session } + Log { LogLevel = Trace, Message = Finished test session. } """, logsString); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { - private const string AssetName = "TestAssetFixture"; + private const string AssetName = "AssetFixture"; public string TargetAssetPath => GetAssetPath(AssetName); @@ -109,28 +104,28 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, serviceProvider) => new DummyTestAdapter(serviceProvider)); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, serviceProvider) => new DummyTestFramework(serviceProvider)); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework, IDataProducer, IOutputDeviceDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer, IOutputDeviceDataProducer { private readonly IOutputDevice _outputDevice; - public DummyTestAdapter(IServiceProvider serviceProvider) + public DummyTestFramework(IServiceProvider serviceProvider) { _outputDevice = serviceProvider.GetOutputDevice(); } - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TelemetryTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TelemetryTests.cs index 48cafde0c2..4c8706a742 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TelemetryTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TelemetryTests.cs @@ -3,29 +3,23 @@ using System.Text.RegularExpressions; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; using Microsoft.Testing.Platform.Configurations; -using Microsoft.Testing.Platform.Helpers; namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class TelemetryTests : AcceptanceTestBase +[TestClass] +public class TelemetryTests : AcceptanceTestBase { private const string AssetName = "TelemetryTest"; - private readonly TestAssetFixture _testAssetFixture; - - public TelemetryTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Telemetry_ByDefault_TelemetryIsEnabled(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic", disableTelemetry: false); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); @@ -40,13 +34,14 @@ public async Task Telemetry_ByDefault_TelemetryIsEnabled(string tfm) await AssertDiagnosticReportAsync(testHostResult, diagPathPattern, diagContentsPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Telemetry_WhenOptingOutTelemetry_WithEnvironmentVariable_TelemetryIsDisabled(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--diagnostic", new Dictionary @@ -67,13 +62,14 @@ public async Task Telemetry_WhenOptingOutTelemetry_WithEnvironmentVariable_Telem await AssertDiagnosticReportAsync(testHostResult, diagPathPattern, diagContentsPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Telemetry_WhenOptingOutTelemetry_With_DOTNET_CLI_EnvironmentVariable_TelemetryIsDisabled(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( "--diagnostic", new Dictionary @@ -94,13 +90,14 @@ public async Task Telemetry_WhenOptingOutTelemetry_With_DOTNET_CLI_EnvironmentVa await AssertDiagnosticReportAsync(testHostResult, diagPathPattern, diagContentsPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Telemetry_WhenEnableTelemetryIsFalse_WithTestApplicationOptions_TelemetryIsDisabled(string tfm) { - string diagPath = Path.Combine(_testAssetFixture.TargetAssetPathWithDisableTelemetry, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPath = Path.Combine(AssetFixture.TargetAssetPathWithDisableTelemetry, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPathWithDisableTelemetry, AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPathWithDisableTelemetry, AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--diagnostic", disableTelemetry: false); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); @@ -138,8 +135,7 @@ private async Task AssertDiagnosticReportAsync(TestHostResult testHostRe return (Regex.IsMatch(content, pattern), content); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string WithTelemetry = nameof(WithTelemetry); private const string WithoutTelemetry = nameof(WithoutTelemetry); @@ -171,21 +167,21 @@ public class Program public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args$TelemetryArg$); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework +public class DummyTestFramework : ITestFramework { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs index a2bcd24716..ea7644e892 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs @@ -1,34 +1,26 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public sealed class TestHostProcessLifetimeHandlerTests : AcceptanceTestBase +[TestClass] +public sealed class TestHostProcessLifetimeHandlerTests : AcceptanceTestBase { private const string AssetName = "TestHostProcessLifetimeHandler"; - private readonly TestAssetFixture _testAssetFixture; - - public TestHostProcessLifetimeHandlerTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task All_Interface_Methods_ShouldBe_Invoked(string currentTfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, AssetName, currentTfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.Success); - Assert.AreEqual(File.ReadAllText(Path.Combine(testHost.DirectoryName, "BeforeTestHostProcessStartAsync.txt")), "TestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync"); - Assert.AreEqual(File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessStartedAsync.txt")), "TestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync"); - Assert.AreEqual(File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessExitedAsync.txt")), "TestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync"); + Assert.AreEqual("TestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync", File.ReadAllText(Path.Combine(testHost.DirectoryName, "BeforeTestHostProcessStartAsync.txt"))); + Assert.AreEqual("TestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync", File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessStartedAsync.txt"))); + Assert.AreEqual("TestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync", File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessExitedAsync.txt"))); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) - : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string Sources = """ #file TestHostProcessLifetimeHandler.csproj @@ -66,7 +58,7 @@ public class Startup public static async Task Main(string[] args) { var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); - testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); testApplicationBuilder.TestHostControllers.AddProcessLifetimeHandler(_ => new TestHostProcessLifetimeHandler()); using ITestApplication app = await testApplicationBuilder.BuildAsync(); return await app.RunAsync(); @@ -107,15 +99,15 @@ public Task OnTestHostProcessStartedAsync(ITestHostProcessInformation testHostPr } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs index fb370f1722..91a7a293f8 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TimeoutTests.cs @@ -1,97 +1,95 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class TimeoutTests : AcceptanceTestBase +[TestClass] +public class TimeoutTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public TimeoutTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithInvalidArg_WithoutLetterSuffix_OutputInvalidMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.StandardError.Contains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithInvalidArg_WithInvalidLetterSuffix_OutputInvalidMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5y"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.StandardError.Contains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithInvalidArg_WithInvalidFormat_OutputInvalidMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 5h6m"); testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); testHostResult.StandardError.Contains("'timeout' option should have one argument as string in the format [h|m|s] where 'value' is float"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithValidArg_WithTestTimeOut_OutputContainsCancelingMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 1s"); testHostResult.AssertExitCodeIsNot(ExitCodes.Success); testHostResult.StandardOutput.Contains("Canceling the test session"); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithValidArg_WithSecondAsSuffix_WithTestNotTimeOut_OutputDoesNotContainCancelingMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 12.5s"); - testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); string output = testHostResult.StandardOutput; Assert.IsFalse(output.Contains("Canceling the test session")); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithValidArg_WithMinuteAsSuffix_WithTestNotTimeOut_OutputDoesNotContainCancelingMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 1m"); - testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); string output = testHostResult.StandardOutput; Assert.IsFalse(output.Contains("Canceling the test session")); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task TimeoutWithValidArg_WithHourAsSuffix_WithTestNotTimeOut_OutputDoesNotContainCancelingMessage(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.NoExtensionTargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--timeout 1h"); - testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); string output = testHostResult.StandardOutput; Assert.IsFalse(output.Contains("Canceling the test session")); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string AssetName = "TimeoutTest"; @@ -107,38 +105,52 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test preview - - - - #file Program.cs -using TimeoutTest; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); - -#file UnitTest1.cs -namespace TimeoutTest; +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Services; -[TestGroup] -public class UnitTest1 +public class Program { - public void TestMethod1() + public static async Task Main(string[] args) { - Assert.IsTrue(true); - Thread.Sleep(10000); + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(), + (_,__) => new DummyTestFramework()); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); } } -#file Usings.cs -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Extensions; +public class DummyTestFramework : ITestFramework +{ + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); + + public string Description => nameof(DummyTestFramework); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + public Task ExecuteRequestAsync(ExecuteRequestContext context) + { + Thread.Sleep(10000); + context.Complete(); + return Task.CompletedTask; + } +} """; public string NoExtensionTargetAssetPath => GetAssetPath(AssetName); @@ -149,8 +161,7 @@ public void TestMethod1() TestCode .PatchTargetFrameworks(TargetFrameworks.All) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); } } } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxTests.cs index 4fd844ccc6..9c86e5770a 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TrxTests.cs @@ -4,23 +4,16 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class TrxTests : AcceptanceTestBase +[TestClass] +public class TrxTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public TrxTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Trx_WhenReportTrxIsNotSpecified_TrxReportIsNotGenerated(string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.Success); @@ -32,20 +25,22 @@ public async Task Trx_WhenReportTrxIsNotSpecified_TrxReportIsNotGenerated(string testHostResult.AssertOutputDoesNotMatchRegex(outputPattern); } - [ArgumentsProvider(nameof(TargetFrameworks.All), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Trx_WhenReportTrxIsSpecified_TrxReportIsGeneratedInDefaultLocation(string tfm) { - string testResultsPath = Path.Combine(_testAssetFixture.TargetAssetPath, "bin", "Release", tfm, "TestResults"); + string testResultsPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, "TestResults"); string trxPathPattern = Path.Combine(testResultsPath, ".*.trx").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--report-trx"); // number of test is the third param because we have two different test code with different number of tests. await AssertTrxReportWasGeneratedAsync(testHostResult, trxPathPattern, 1); } - [ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Trx_WhenTestHostCrash_ErrorIsDisplayedInsideTheTrx(string tfm) { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) @@ -55,7 +50,7 @@ public async Task Trx_WhenTestHostCrash_ErrorIsDisplayedInsideTheTrx(string tfm) } string fileName = Guid.NewGuid().ToString("N"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, TestAssetFixture.AssetName, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, TestAssetFixture.AssetName, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync( $"--crashdump --report-trx --report-trx-filename {fileName}.trx", new() { { "CRASHPROCESS", "1" } }); @@ -64,15 +59,16 @@ public async Task Trx_WhenTestHostCrash_ErrorIsDisplayedInsideTheTrx(string tfm) string trxFile = Directory.GetFiles(testHost.DirectoryName, $"{fileName}.trx", SearchOption.AllDirectories).Single(); string trxContent = File.ReadAllText(trxFile); - Assert.That(Regex.IsMatch(trxContent, @"Test host process pid: .* crashed\."), trxContent); - Assert.That(trxContent.Contains(""""""), trxContent); + Assert.IsTrue(Regex.IsMatch(trxContent, @"Test host process pid: .* crashed\."), trxContent); + StringAssert.Contains(trxContent, """""", trxContent); } - [ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Trx_WhenSkipTest_ItAppearsAsExpectedInsideTheTrx(string tfm) { string fileName = Guid.NewGuid().ToString("N"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPathWithSkippedTest, TestAssetFixture.AssetNameUsingMSTest, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPathWithSkippedTest, TestAssetFixture.AssetNameUsingMSTest, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync($"--report-trx --report-trx-filename {fileName}.trx"); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); @@ -82,33 +78,34 @@ public async Task Trx_WhenSkipTest_ItAppearsAsExpectedInsideTheTrx(string tfm) string trxContent = File.ReadAllText(trxFile); // check if the tests have been added to Results, TestDefinitions, TestEntries and ResultSummary. - Assert.That(trxContent.Contains(@""""), trxContent); - Assert.That(trxContent.Contains(""""""), trxContent); + StringAssert.Contains(trxContent, @"""", trxContent); + StringAssert.Contains(trxContent, """""", trxContent); } - [ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Trx_WhenTheTestNameHasInvalidXmlChar_TheTrxCreatedSuccessfully(string tfm) { - string testResultsPath = Path.Combine(_testAssetFixture.TargetAssetPathWithDataRow, "bin", "Release", tfm, "TestResults"); + string testResultsPath = Path.Combine(AssetFixture.TargetAssetPathWithDataRow, "bin", "Release", tfm, "TestResults"); string trxPathPattern = Path.Combine(testResultsPath, ".*.trx").Replace(@"\", @"\\"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPathWithDataRow, TestAssetFixture.AssetNameUsingMSTest, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPathWithDataRow, TestAssetFixture.AssetNameUsingMSTest, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync("--report-trx"); // number of test is the third param because we have two different test code with different number of tests. await AssertTrxReportWasGeneratedAsync(testHostResult, trxPathPattern, 2); } - [ArgumentsProvider(nameof(TargetFrameworks.Net), typeof(TargetFrameworks))] + [DynamicData(nameof(TargetFrameworks.NetForDynamicData), typeof(TargetFrameworks))] + [TestMethod] public async Task Trx_UsingDataDriven_CreatesUnitTestTagForEachOneInsideTheTrx(string tfm) { string fileName = Guid.NewGuid().ToString("N"); - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPathWithSkippedTest, TestAssetFixture.AssetNameUsingMSTest, tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPathWithSkippedTest, TestAssetFixture.AssetNameUsingMSTest, tfm); TestHostResult testHostResult = await testHost.ExecuteAsync($"--report-trx --report-trx-filename {fileName}.trx"); testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); @@ -122,47 +119,51 @@ public async Task Trx_UsingDataDriven_CreatesUnitTestTagForEachOneInsideTheTrx(s \s* CheckTrxContentsMatchAsync(string path, string pattern) return Regex.IsMatch(await reader.ReadToEndAsync(), pattern); } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { public const string AssetName = "TrxTest"; public const string AssetNameUsingMSTest = "TrxTestUsingMSTest"; @@ -218,45 +218,73 @@ public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : Test - - - - - #file Program.cs -using TrxTest; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); -builder.AddCrashDumpProvider(); -builder.AddTrxReportProvider(); -using ITestApplication app = await builder.BuildAsync(); -return await app.RunAsync(); +using Microsoft.Testing.Extensions; +using Microsoft.Testing.Extensions.TrxReport.Abstractions; +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.TestFramework; +using Microsoft.Testing.Platform.Services; + +public class Program +{ + public static async Task Main(string[] args) + { + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + builder.RegisterTestFramework( + sp => new TestFrameworkCapabilities(new TrxReportCapability()), + (_,__) => new DummyTestFramework()); + builder.AddCrashDumpProvider(); + builder.AddTrxReportProvider(); + using ITestApplication app = await builder.BuildAsync(); + return await app.RunAsync(); + } +} -#file UnitTest1.cs -namespace TrxTest; +public class TrxReportCapability : ITrxReportCapability +{ + bool ITrxReportCapability.IsSupported { get; } = true; + void ITrxReportCapability.Enable() + { + } +} -[TestGroup] -public class UnitTest1 +public class DummyTestFramework : ITestFramework, IDataProducer { - public void TestMethod1() + public string Uid => nameof(DummyTestFramework); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestFramework); + + public string Description => nameof(DummyTestFramework); + + public Type[] DataTypesProduced => new[] { typeof(TestNodeUpdateMessage) }; + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + + public async Task ExecuteRequestAsync(ExecuteRequestContext context) { if (Environment.GetEnvironmentVariable("CRASHPROCESS") == "1") { Environment.FailFast("CRASHPROCESS"); } - Assert.IsTrue(true); + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "0", DisplayName = "Test", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); + context.Complete(); } } - -#file Usings.cs -global using System; -global using Microsoft.Testing.Platform.Builder; -global using Microsoft.Testing.Internal.Framework; -global using Microsoft.Testing.Extensions; """; private const string MSTestCode = """ @@ -270,6 +298,7 @@ public void TestMethod1() true preview true + false @@ -319,8 +348,7 @@ public void TestMethod1(string s) TestCode .PatchTargetFrameworks(TargetFrameworks.All) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) - .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion) - .PatchCodeWithReplace("$MicrosoftTestingInternalFrameworkVersion$", MicrosoftTestingInternalFrameworkVersion)); + .PatchCodeWithReplace("$MicrosoftTestingEnterpriseExtensionsVersion$", MicrosoftTestingEnterpriseExtensionsVersion)); yield return (WithSkippedTest, AssetNameUsingMSTest, MSTestCode .PatchTargetFrameworks(TargetFrameworks.All) diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/UnhandledExceptionPolicyTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/UnhandledExceptionPolicyTests.cs index 209cd2005f..004d1aeb94 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/UnhandledExceptionPolicyTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/UnhandledExceptionPolicyTests.cs @@ -3,19 +3,11 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; -using Microsoft.Testing.Platform.Helpers; - namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; -[TestGroup] -public class UnhandledExceptionPolicyTests : AcceptanceTestBase +[TestClass] +public class UnhandledExceptionPolicyTests : AcceptanceTestBase { - private readonly TestAssetFixture _testAssetFixture; - - public UnhandledExceptionPolicyTests(ITestExecutionContext testExecutionContext, TestAssetFixture testAssetFixture) - : base(testExecutionContext) => _testAssetFixture = testAssetFixture; - public enum Mode { Enabled, @@ -25,22 +17,23 @@ public enum Mode Default, } - internal static IEnumerable> ModeProvider() + internal static IEnumerable<(Mode Mode, string Arguments)> ModeProvider() { - foreach (TestArgumentsEntry tfm in TargetFrameworks.All) + foreach (string tfm in TargetFrameworks.All) { - yield return new TestArgumentsEntry<(Mode, string)>((Mode.Enabled, tfm.Arguments), $"Enabled - {tfm.Arguments}"); - yield return new TestArgumentsEntry<(Mode, string)>((Mode.Disabled, tfm.Arguments), $"Disabled - {tfm.Arguments}"); - yield return new TestArgumentsEntry<(Mode, string)>((Mode.DisabledByEnvironmentVariable, tfm.Arguments), $"DisabledByEnvironmentVariable - {tfm.Arguments}"); - yield return new TestArgumentsEntry<(Mode, string)>((Mode.EnabledByEnvironmentVariable, tfm.Arguments), $"EnabledByEnvironmentVariable - {tfm.Arguments}"); - yield return new TestArgumentsEntry<(Mode, string)>((Mode.Default, tfm.Arguments), $"Default - ({tfm.Arguments})"); + yield return new(Mode.Enabled, tfm); + yield return new(Mode.Disabled, tfm); + yield return new(Mode.DisabledByEnvironmentVariable, tfm); + yield return new(Mode.EnabledByEnvironmentVariable, tfm); + yield return new(Mode.Default, tfm); } } - [ArgumentsProvider(nameof(ModeProvider))] + [DynamicData(nameof(ModeProvider), DynamicDataSourceType.Method)] + [TestMethod] public async Task UnhandledExceptionPolicy_ConfigFile_UnobservedTaskException_ShouldCrashProcessIfEnabled(Mode mode, string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "UnhandledExceptionPolicyTests", tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "UnhandledExceptionPolicyTests", tfm); using TempDirectory clone = new(); await clone.CopyDirectoryAsync(testHost.DirectoryName, clone.Path, retainAttributes: !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); testHost = TestInfrastructure.TestHost.LocateFrom(clone.Path, "UnhandledExceptionPolicyTests"); @@ -93,10 +86,11 @@ public async Task UnhandledExceptionPolicy_ConfigFile_UnobservedTaskException_Sh } } - [ArgumentsProvider(nameof(ModeProvider))] + [DynamicData(nameof(ModeProvider), DynamicDataSourceType.Method)] + [TestMethod] public async Task UnhandledExceptionPolicy_EnvironmentVariable_UnhandledException_ShouldCrashProcessIfEnabled(Mode mode, string tfm) { - var testHost = TestInfrastructure.TestHost.LocateFrom(_testAssetFixture.TargetAssetPath, "UnhandledExceptionPolicyTests", tfm); + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, "UnhandledExceptionPolicyTests", tfm); using TempDirectory clone = new(); await clone.CopyDirectoryAsync(testHost.DirectoryName, clone.Path, retainAttributes: !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); testHost = TestInfrastructure.TestHost.LocateFrom(clone.Path, "UnhandledExceptionPolicyTests"); @@ -151,8 +145,7 @@ public async Task UnhandledExceptionPolicy_EnvironmentVariable_UnhandledExceptio } } - [TestFixture(TestFixtureSharingStrategy.PerTestGroup)] - public sealed class TestAssetFixture(AcceptanceFixture acceptanceFixture) : TestAssetFixtureBase(acceptanceFixture.NuGetGlobalPackagesFolder) + public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) { private const string AssetName = "UnhandledExceptionPolicyTests"; @@ -208,21 +201,21 @@ public class Startup public static async Task Main(string[] args) { ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); - builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestAdapter()); + builder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_,__) => new DummyTestFramework()); using ITestApplication app = await builder.BuildAsync(); return await app.RunAsync(); } } -public class DummyTestAdapter : ITestFramework, IDataProducer +public class DummyTestFramework : ITestFramework, IDataProducer { - public string Uid => nameof(DummyTestAdapter); + public string Uid => nameof(DummyTestFramework); public string Version => "2.0.0"; - public string DisplayName => nameof(DummyTestAdapter); + public string DisplayName => nameof(DummyTestFramework); - public string Description => nameof(DummyTestAdapter); + public string Description => nameof(DummyTestFramework); public Task IsEnabledAsync() => Task.FromResult(true); diff --git a/test/Performance/MSTest.Performance.Runner/Program.cs b/test/Performance/MSTest.Performance.Runner/Program.cs index c5e424ee05..11775c0650 100644 --- a/test/Performance/MSTest.Performance.Runner/Program.cs +++ b/test/Performance/MSTest.Performance.Runner/Program.cs @@ -5,10 +5,15 @@ using System.Runtime.InteropServices; using Microsoft.Testing.TestInfrastructure; +using Microsoft.VisualStudio.TestTools.UnitTesting; using MSTest.Performance.Runner.Steps; using DotnetMuxer = MSTest.Performance.Runner.Steps.DotnetMuxer; +using ExecutionScope = MSTest.Performance.Runner.Steps.ExecutionScope; + +// TODO: this should not be required +[assembly: Parallelize(Scope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.MethodLevel, Workers = 0)] namespace MSTest.Performance.Runner; diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyCleanupShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyCleanupShouldBeValidAnalyzerTests.cs index ad6c0b52bb..895d940aad 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyCleanupShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyCleanupShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class AssemblyCleanupShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class AssemblyCleanupShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenAssemblyCleanupIsPublic_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public static void AssemblyCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyCleanIsInsideAGenericClass_Diagnostic() { string code = """ @@ -49,6 +51,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenAssemblyCleanupIsNotOrdinary_Diagnostic() { string code = """ @@ -70,6 +73,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenAssemblyCleanupIsPublic_InsideInternalClassWithDiscoverInternals_NoDiagnostic() { string code = """ @@ -90,6 +94,7 @@ public static void AssemblyCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyCleanupIsInternal_InsidePublicClassWithDiscoverInternals_Diagnostic() { string code = """ @@ -128,10 +133,11 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenAssemblyCleanupIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -166,6 +172,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyCleanupIsGeneric_Diagnostic() { string code = """ @@ -200,6 +207,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyCleanupIsNotStatic_Diagnostic() { string code = """ @@ -234,6 +242,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyCleanupHasParameters_Diagnostic() { string code = """ @@ -268,6 +277,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyCleanupReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -375,6 +385,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyCleanupReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -406,6 +417,7 @@ public static ValueTask AssemblyCleanup2() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyCleanupIsAsyncVoid_Diagnostic() { string code = """ @@ -444,6 +456,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenMultipleViolations_TheyAllGetFixed() { string code = """ @@ -482,6 +495,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyCleanupIsNotOnClass_Diagnostic() { string code = """ @@ -499,6 +513,7 @@ public struct MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyCleanupIsOnClassNotMarkedWithTestClass_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyInitializeShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyInitializeShouldBeValidAnalyzerTests.cs index b6d2a58b3f..e7ffa9a0fe 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyInitializeShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AssemblyInitializeShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class AssemblyInitializeShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class AssemblyInitializeShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenAssemblyInitializeIsPublic_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public static void AssemblyInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyInitializeIsPublic_InsideInternalClassWithDiscoverInternals_NoDiagnostic() { string code = """ @@ -48,6 +50,7 @@ public static void AssemblyInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyInitializeIsInsideAGenericClass_Diagnostic() { string code = """ @@ -69,6 +72,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenAssemblyInitializeIsInternal_InsidePublicClassWithDiscoverInternals_Diagnostic() { string code = """ @@ -107,10 +111,11 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenAssemblyInitializeIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -145,6 +150,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyInitializeIsNotOrdinary_Diagnostic() { string code = """ @@ -166,6 +172,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenAssemblyInitializeIsGeneric_Diagnostic() { string code = """ @@ -200,6 +207,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyInitializeIsNotStatic_Diagnostic() { string code = """ @@ -234,6 +242,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyInitializeDoesNotHaveParameters_Diagnostic() { string code = """ @@ -268,6 +277,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyInitializeReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -371,6 +381,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyInitializeReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -402,6 +413,7 @@ public static ValueTask AssemblyInitialize2(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyInitializeIsAsyncVoid_Diagnostic() { string code = """ @@ -440,6 +452,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenMultipleViolations_TheyAllGetFixed() { string code = """ @@ -478,6 +491,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssemblyInitializeIsNotOnClass_Diagnostic() { string code = """ @@ -495,6 +509,7 @@ public struct MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssemblyInitializeIsOnClassNotMarkedWithTestClass_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldAvoidConditionalAccessAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldAvoidConditionalAccessAnalyzerTests.cs index f045776241..2a7f2b5ecc 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldAvoidConditionalAccessAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldAvoidConditionalAccessAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.UnitTests; -[TestGroup] -public sealed class AssertionArgsShouldAvoidConditionalAccessAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class AssertionArgsShouldAvoidConditionalAccessAnalyzerTests { + [TestMethod] public async Task WhenUsingConditionalsAccess_In_Assert_Equal() { string code = """ @@ -99,6 +100,7 @@ public void Compliant() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenUsingConditionalsAccess_In_Assert_Boolean() { string code = """ @@ -158,6 +160,7 @@ public void Compliant() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenUsingConditionalsAccess_In_NullAssertions_Gives_NoWarning() { string code = """ @@ -187,6 +190,7 @@ public void Compliant() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenUsingConditionalsAccess_In_CollectionAssert() { string code = """ @@ -258,6 +262,7 @@ public void Compliant() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenUsingConditionalsAccess_In_StringAssert() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldBePassedInCorrectOrderAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldBePassedInCorrectOrderAnalyzerTests.cs index 413be9c844..2084f21415 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldBePassedInCorrectOrderAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AssertionArgsShouldBePassedInCorrectOrderAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.UnitTests; -[TestGroup] -public sealed class AssertionArgsShouldBePassedInCorrectOrderAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class AssertionArgsShouldBePassedInCorrectOrderAnalyzerTests { + [TestMethod] public async Task WhenUsingLiterals() { string code = """ @@ -161,6 +162,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task LiteralUsingNamedArgument() { string code = """ @@ -292,6 +294,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task ConstantValue() { string code = """ @@ -437,6 +440,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task ActualAsLocalVariableOrNot() { string code = """ @@ -501,6 +505,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task ActualOrExpectedPrefix() { string code = """ @@ -702,6 +707,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task MethodCalls() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidExpectedExceptionAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidExpectedExceptionAttributeAnalyzerTests.cs index 15e99f9f67..f194c77ce6 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidExpectedExceptionAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/AvoidExpectedExceptionAttributeAnalyzerTests.cs @@ -9,9 +9,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class AvoidExpectedExceptionAttributeAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class AvoidExpectedExceptionAttributeAnalyzerTests { + [TestMethod] public async Task WhenUsed_Diagnostic() { string code = """ @@ -121,6 +122,7 @@ public void TestMethod2() await test.RunAsync(CancellationToken.None); } + [TestMethod] public async Task When_Statement_Block_Diagnostic() { string code = """ @@ -157,6 +159,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_Statement_ExpressionBody_Diagnostic() { string code = """ @@ -189,6 +192,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_Expression_Block_Diagnostic() { string code = """ @@ -229,6 +233,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_Expression_ExpressionBody_Diagnostic() { string code = """ @@ -264,6 +269,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_Async_Block_Diagnostic() { string code = """ @@ -302,6 +308,7 @@ public async Task TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_Async_ExpressionBody_Diagnostic() { string code = """ @@ -336,6 +343,7 @@ public async Task TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_TestMethodIsAsyncButLastStatementIsSynchronous_Diagnostic() { string code = """ @@ -380,6 +388,7 @@ public async Task TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task When_LastStatementHasDeepAwait_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/ClassCleanupShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/ClassCleanupShouldBeValidAnalyzerTests.cs index 7fee442876..5c202bd625 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/ClassCleanupShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/ClassCleanupShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class ClassCleanupShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class ClassCleanupShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenClassCleanupIsPublic_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsGenericWithInheritanceModeSet_NoDiagnostic() { string code = """ @@ -46,6 +48,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsGenericWithInheritanceModeSetToNone_Diagnostic() { string code = """ @@ -67,6 +70,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassCleanupIsGenericWithoutSettingInheritanceMode_Diagnostic() { string code = """ @@ -88,6 +92,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassCleanupIsNotOrdinary_Diagnostic() { string code = """ @@ -109,6 +114,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassCleanupIsPublic_InsideInternalClassWithDiscoverInternals_NoDiagnostic() { string code = """ @@ -129,6 +135,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsInternal_InsidePublicClassWithDiscoverInternals_Diagnostic() { string code = """ @@ -167,10 +174,11 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenClassCleanupIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -205,6 +213,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassCleanupIsGeneric_Diagnostic() { string code = """ @@ -239,6 +248,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassCleanupIsNotStatic_Diagnostic() { string code = """ @@ -273,6 +283,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassCleanupHasParameters_Diagnostic() { string code = """ @@ -307,6 +318,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassCleanupReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -382,6 +394,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassCleanupReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -413,6 +426,7 @@ public static ValueTask ClassCleanup2() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsAsyncVoid_Diagnostic() { string code = """ @@ -451,6 +465,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenMultipleViolations_TheyAllGetFixed() { string code = """ @@ -489,6 +504,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassCleanupIsNotOnClass_Diagnostic() { string code = """ @@ -506,6 +522,7 @@ public struct MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnSealedClassNotMarkedWithTestClass_Diagnostic() { string code = """ @@ -523,6 +540,7 @@ public sealed class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnNonSealedClassNotMarkedWithTestClass_NoDiagnostic() { string code = """ @@ -540,6 +558,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnAbstractClassNotMarkedWithTestClass_AndWithInheritanceBehavior_NoDiagnostic() { string code = """ @@ -557,6 +576,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnAbstractClassMarkedWithTestClass_AndWithInheritanceBehavior_NoDiagnostic() { string code = """ @@ -575,6 +595,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsAbstractClassNotMarkedWithTestClass_AndWithoutInheritanceBehavior_Diagnostic() { string code = """ @@ -592,6 +613,7 @@ public abstract class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnAbstractClassMarkedWithTestClass_AndWithoutInheritanceBehavior_Diagnostic() { string code = """ @@ -610,6 +632,7 @@ public abstract class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnAbstractClassMarkedWithTestClass_AndWithInheritanceBehaviorNone_Diagnostic() { string code = """ @@ -628,6 +651,7 @@ public abstract class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnSealedClassMarkedWithTestClass_AndWithInheritanceBehavior_Diagnostic() { string code = """ @@ -646,6 +670,7 @@ public sealed class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnSealedClassMarkedWithTestClass_AndWithInheritanceBehaviorNone_NoDiagnostic() { string code = """ @@ -664,6 +689,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassCleanupIsOnSealedClassMarkedWithTestClass_WithDefaultInheritanceBehavior_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/ClassInitializeShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/ClassInitializeShouldBeValidAnalyzerTests.cs index 171807825d..55cc137e6f 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/ClassInitializeShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/ClassInitializeShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class ClassInitializeShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class ClassInitializeShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenClassInitializeIsPublic_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsGenericWithInheritanceModeSet_NoDiagnostic() { string code = """ @@ -46,6 +48,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsGenericWithInheritanceModeSetToNone_Diagnostic() { string code = """ @@ -67,6 +70,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassInitializeIsGenericWithoutSettingInheritanceMode_Diagnostic() { string code = """ @@ -88,6 +92,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassInitializeIsPublic_InsideInternalClassWithDiscoverInternals_NoDiagnostic() { string code = """ @@ -108,6 +113,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsInternal_InsidePublicClassWithDiscoverInternals_Diagnostic() { string code = """ @@ -148,10 +154,11 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenClassInitializeIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -186,6 +193,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassInitializeIsNotOrdinary_Diagnostic() { string code = """ @@ -207,6 +215,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassInitializeIsGeneric_Diagnostic() { string code = """ @@ -241,6 +250,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassInitializeIsNotStatic_Diagnostic() { string code = """ @@ -275,6 +285,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassInitializeDoesNotHaveParameters_Diagnostic() { string code = """ @@ -309,6 +320,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassInitializeReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -384,6 +396,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassInitializeReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -415,6 +428,7 @@ public static ValueTask ClassInitialize2(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsAsyncVoid_Diagnostic() { string code = """ @@ -453,6 +467,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenMultipleViolations_TheyAllGetFixed() { string code = """ @@ -491,6 +506,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassInitializeIsNotOnClass_Diagnostic() { string code = """ @@ -508,6 +524,7 @@ public struct MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnSealedClassNotMarkedWithTestClass_Diagnostic() { string code = """ @@ -525,6 +542,7 @@ public sealed class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnNonSealedClassNotMarkedWithTestClass_NoDiagnostic() { string code = """ @@ -542,6 +560,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnAbstractClassNotMarkedWithTestClass_AndWithInheritanceBehavior_NoDiagnostic() { string code = """ @@ -559,6 +578,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnAbstractClassMarkedWithTestClass_AndWithInheritanceBehavior_NoDiagnostic() { string code = """ @@ -577,6 +597,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsAbstractClassNotMarkedWithTestClass_AndWithoutInheritanceBehavior_Diagnostic() { string code = """ @@ -594,6 +615,7 @@ public abstract class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnAbstractClassMarkedWithTestClass_AndWithoutInheritanceBehavior_Diagnostic() { string code = """ @@ -612,6 +634,7 @@ public abstract class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnAbstractClassMarkedWithTestClass_AndWithInheritanceBehaviorNone_Diagnostic() { string code = """ @@ -630,6 +653,7 @@ public abstract class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnSealedClassMarkedWithTestClass_AndWithInheritanceBehavior_Diagnostic() { string code = """ @@ -648,6 +672,7 @@ public sealed class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnSealedClassMarkedWithTestClass_AndWithInheritanceBehaviorNone_NoDiagnostic() { string code = """ @@ -666,6 +691,7 @@ public static void ClassInitialize(TestContext testContext) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassInitializeIsOnSealedClassMarkedWithTestClass_AndDefaultInheritanceBehavior_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DataRowShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DataRowShouldBeValidAnalyzerTests.cs index c5a50491a8..37e2ced325 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DataRowShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DataRowShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class DataRowShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class DataRowShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgument_NoDiagnostic() { string code = """ @@ -29,6 +30,7 @@ public void TestMethod1(int a) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndWithDataTestMethodAttribute_NoDiagnostic() { string code = """ @@ -48,6 +50,7 @@ public void TestMethod1(int a) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndWithDerivedTestMethodAttribute_NoDiagnostic() { string code = """ @@ -71,6 +74,7 @@ public void TestMethod1(int a) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithThreeArguments_NoDiagnostic() { string code = """ @@ -90,6 +94,7 @@ public void TestMethod1(int a, int b, int c) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithThreeArgumentsAndMethodHasParamsArgument_NoDiagnostic() { string code = """ @@ -109,6 +114,7 @@ public void TestMethod1(params object[] o) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithThreeArgumentsAndMethodHasArrayArgument_NoDiagnostic() { string code = """ @@ -128,6 +134,7 @@ public void TestMethod1(object[] o) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowPassesOneItemAndParameterExpectsArray_Diagnostic() { string code = """ @@ -151,6 +158,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments((0, 0))); } + [TestMethod] public async Task WhenDataRowHasThreeArgumentsAndMethodHasAnIntegerAndAnArrayArgument_Diagnostic() { string code = """ @@ -174,6 +182,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments(3, 2)); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndMethodHasAPrimitiveTypeAndAParamsArgument_NoDiagnostic() { string code = """ @@ -193,6 +202,7 @@ public void TestMethod1(int a, params object[] o) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithThreeArgumentsAndMethodHasAPrimitiveTypeAndAParamsArgument_NoDiagnostic() { string code = """ @@ -212,6 +222,7 @@ public void TestMethod1(int a, params object[] o) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndMethodHasAPrimitiveTypeAndAParamsStringArgument_NoDiagnostic() { string code = """ @@ -231,6 +242,7 @@ public void TestMethod1(int a, params string[] o) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndMethodHasAPrimitiveTypeAndADefaultArgument_NoDiagnostic() { string code = """ @@ -252,6 +264,7 @@ public void TestMethod1(int a, object?[]? o = null) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndIntegersAreAssignableToDoubles_NoDiagnostic() { string code = """ @@ -271,6 +284,7 @@ public void TestMethod1(double d) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndCharsAreAssignableToIntegers_NoDiagnostic() { string code = """ @@ -290,6 +304,7 @@ public void TestMethod1(int i) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowIsCorrectlyDefinedWithOneArgumentAndNullsAreAssignableToIntegers_NoDiagnostic() { string code = """ @@ -309,6 +324,7 @@ public void TestMethod1(int i) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataRowHasOneNullArgumentAndMethodHasNoArguments_Diagnostic() { string code = """ @@ -332,6 +348,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments(1, 0)); } + [TestMethod] public async Task WhenDataRowIsNotSetOnATestMethod_Diagnostic() { string code = """ @@ -351,6 +368,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code, VerifyCS.Diagnostic(DataRowShouldBeValidAnalyzer.DataRowOnTestMethodRule).WithLocation(0)); } + [TestMethod] public async Task WhenDataRowHasNoArgsButMethodHasOneArgument_Diagnostic() { string code = """ @@ -375,6 +393,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments(0, 1)); } + [TestMethod] public async Task WhenDataRowHasArgumentMismatchWithTestMethod_Diagnostic() { string code = """ @@ -399,6 +418,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments(3, 4)); } + [TestMethod] public async Task WhenDataRowHasArgumentMismatchWithTestMethod2_Diagnostic() { string code = """ @@ -423,6 +443,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments(3, 2)); } + [TestMethod] public async Task WhenDataRowHasArgumentMismatchWithTestMethod3_Diagnostic() { string code = """ @@ -447,6 +468,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments(3, 2)); } + [TestMethod] public async Task WhenDataRowHasTypeMismatchWithTestMethod_Diagnostic() { string code = """ @@ -471,6 +493,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments((2, 2))); } + [TestMethod] public async Task DefaultArguments() { string code = """ @@ -508,6 +531,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DataRowShouldBeValidAnalyzer.ArgumentCountMismatchRule).WithLocation(2).WithArguments(1, 5)); } + [TestMethod] public async Task Testfx_2606_NullArgumentForArray() { string code = """ @@ -540,6 +564,7 @@ public void TestSomething( await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task Issue2856_ArraysInDataRow_NoDiagnostic() { string code = """ @@ -561,6 +586,7 @@ public void ItemsTest(int[] input) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenMethodIsGeneric() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotNegateBooleanAssertionAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotNegateBooleanAssertionAnalyzerTests.cs index efcad90561..f4e145e21e 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotNegateBooleanAssertionAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotNegateBooleanAssertionAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class DoNotNegateBooleanAssertionAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class DoNotNegateBooleanAssertionAnalyzerTests { + [TestMethod] public async Task WhenAssertionIsNotNegated_NoDiagnostic() { string code = """ @@ -41,6 +42,7 @@ public void TestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssertionIsNegated_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotStoreStaticTestContextAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotStoreStaticTestContextAnalyzerTests.cs index 5cb352dbce..f0c3590176 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotStoreStaticTestContextAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotStoreStaticTestContextAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class DoNotStoreStaticTestContextAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class DoNotStoreStaticTestContextAnalyzerTests { + [TestMethod] public async Task WhenAssemblyInitializeOrClassInitialize_Diagnostic() { string code = """ @@ -87,6 +88,7 @@ public static ValueTask ClassInit(TestContext tc) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenOtherTestContext_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs index a4196dc747..8b471471e3 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class DoNotUseShadowingAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class DoNotUseShadowingAnalyzerTests { + [TestMethod] public async Task WhenTestClassHaveShadowingMethod_Diagnostic() { string code = """ @@ -29,6 +30,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_ButDifferentParameters_NoDiagnostic() { string code = """ @@ -48,6 +50,7 @@ public void Method() { } await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_ButBothArePrivate_NoDiagnostic() { string code = """ @@ -67,6 +70,7 @@ private void Method() { } await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_ButBaseMethodIsPrivate_NoDiagnostic() { string code = """ @@ -86,6 +90,7 @@ public void Method() { } await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_ButDerivedMethodIsPrivate_Diagnostic() { string code = """ @@ -105,6 +110,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_ButDerivedMethodIsProtected_AndBaseMethodIsInternal_Diagnostic() { string code = """ @@ -124,6 +130,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSamePropertyAsBaseClassMethod__ButBasePropertyIsProtected_AndDerivedPropertyIsInternal_Diagnostic() { string code = """ @@ -143,6 +150,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSamePropertyAsBaseClassMethod_ButBothArePrivate_NoDiagnostic() { string code = """ @@ -162,6 +170,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSamePropertyAsBaseClassMethod_ButBasePropertyIsPrivate_NoDiagnostic() { string code = """ @@ -181,6 +190,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSamePropertyAsBaseClassMethod_ButDerivedPropertyIsPrivate_Diagnostic() { string code = """ @@ -200,6 +210,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_ButOneIsGeneric_NoDiagnostic() { string code = """ @@ -231,6 +242,7 @@ public class SomeType await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveSameMethodAsBaseClassMethod_WithParameters_Diagnostic() { string code = """ @@ -250,6 +262,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveOverrideProperty_NoDiagnostic() { string code = """ @@ -269,6 +282,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassOverrideMethodFromBaseClass_NoDiagnostic() { string code = """ @@ -288,6 +302,7 @@ public override void Method() { } await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveShadowingProperty_Diagnostic() { string code = """ @@ -307,6 +322,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveShadowingMethod_WithoutNewModifier_Diagnostic() { string code = """ @@ -326,6 +342,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassHaveShadowingProperty_WithoutNewModifier_Diagnostic() { string code = """ @@ -345,6 +362,7 @@ public class DerivedClass : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassAndBaseClassHaveStaticCtor_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseSystemDescriptionAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseSystemDescriptionAttributeAnalyzerTests.cs index de809f42f0..e5c2dd3cd7 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseSystemDescriptionAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseSystemDescriptionAttributeAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class DoNotUseSystemDescriptionAttributeAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class DoNotUseSystemDescriptionAttributeAnalyzerTests { + [TestMethod] public async Task WhenTestMethodHasMicrosoftDescriptionAttribute_NoDiagnostic() { string code = """ @@ -29,6 +30,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestMethodHasSystemDescriptionAttribute_Diagnostic() { string code = """ @@ -48,6 +50,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenMethodWithoutTestMethodAttribute_HasSystemDescriptionAttribute_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs index b15c8c2c9d..b572150cc1 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DynamicDataShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class DynamicDataShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class DynamicDataShouldBeValidAnalyzerTests { + [TestMethod] public async Task ValidUsages_NoDiagnostic() { string code = """ @@ -290,6 +291,7 @@ public class SomeClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDataSourceMemberDoesNotExist_Diagnostic() { string code = """ @@ -364,6 +366,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.MemberNotFoundRule).WithLocation(7).WithArguments("SomeClass", "MemberNotFound")); } + [TestMethod] public async Task WhenAppliedToNonTestMethod_Diagnostic() { string code = """ @@ -406,6 +409,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.NotTestMethodRule).WithLocation(3)); } + [TestMethod] public async Task WhenDataSourceMemberFoundMultipleTimes_Diagnostic() { string code = """ @@ -458,6 +462,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.FoundTooManyMembersRule).WithLocation(3).WithArguments("SomeClass", "GetSomeData")); } + [TestMethod] public async Task WhenMemberKindIsMixedUp_Diagnostic() { string code = """ @@ -538,6 +543,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.SourceTypePropertyRule).WithLocation(7).WithArguments("SomeClass", "SomeData")); } + [TestMethod] public async Task WhenDataSourceReturnTypeIsInvalid_Diagnostic() { string code = """ @@ -678,6 +684,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.MemberTypeRule).WithLocation(15).WithArguments("SomeClass", "GetSomeDataArray")); } + [TestMethod] public async Task MemberIsNotStatic_Diagnostic() { string code = """ @@ -711,6 +718,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(1).WithArguments("MyTestClass", "GetData")); } + [TestMethod] public async Task MemberIsNotPublic_NoDiagnostic() { string code = """ @@ -741,6 +749,7 @@ public void TestMethod2(object[] o) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task MethodHasParameters_Diagnostic() { string code = """ @@ -774,6 +783,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(1).WithArguments("MyTestClass", "GetData2")); } + [TestMethod] public async Task MethodIsGeneric_Diagnostic() { string code = """ @@ -799,6 +809,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DataMemberSignatureRule).WithLocation(0).WithArguments("MyTestClass", "GetData")); } + [TestMethod] public async Task WhenDisplayMemberIsValid_NoDiagnostic() { string code = """ @@ -873,6 +884,7 @@ public class SomeClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDisplayMemberIsNotFound_Diagnostic() { string code = """ @@ -924,6 +936,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.MemberNotFoundRule).WithLocation(3).WithArguments("SomeClass", "MemberNotFound")); } + [TestMethod] public async Task WhenDisplayMemberIsNotPublic_Diagnostic() { string code = """ @@ -979,6 +992,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DisplayMethodSignatureRule).WithLocation(3).WithArguments("SomeClass", "GetSomeDisplayName")); } + [TestMethod] public async Task WhenDisplayMemberIsNotStatic_Diagnostic() { string code = """ @@ -1034,6 +1048,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DisplayMethodSignatureRule).WithLocation(3).WithArguments("SomeClass", "GetSomeDisplayName")); } + [TestMethod] public async Task WhenDisplayMemberDoesNotReturnString_Diagnostic() { string code = """ @@ -1089,6 +1104,7 @@ await VerifyCS.VerifyAnalyzerAsync( VerifyCS.Diagnostic(DynamicDataShouldBeValidAnalyzer.DisplayMethodSignatureRule).WithLocation(3).WithArguments("SomeClass", "GetSomeDisplayName")); } + [TestMethod] public async Task WhenDisplayMemberInvalidParameters_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj b/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj index b9dbd809a1..48717386f5 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj @@ -3,9 +3,9 @@ net6.0 false + true true true - true diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/NonNullableReferenceNotInitializedSuppressorTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/NonNullableReferenceNotInitializedSuppressorTests.cs index 12c094c2c4..32cff434a9 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/NonNullableReferenceNotInitializedSuppressorTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/NonNullableReferenceNotInitializedSuppressorTests.cs @@ -13,9 +13,10 @@ namespace MSTest.Analyzers.UnitTests; -[TestGroup] -public sealed class NonNullableReferenceNotInitializedSuppressorTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class NonNullableReferenceNotInitializedSuppressorTests { + [TestMethod] public async Task TestContextPropertyOnTestClass_DiagnosticIsSuppressed() { string code = @" @@ -43,6 +44,7 @@ public class SomeClass }.RunAsync(); } + [TestMethod] public async Task TestContextPropertyOnNonTestClass_DiagnosticIsNotSuppressed() { string code = @" diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests.cs index b2c05361d5..69f3b533a6 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PreferAssertFailOverAlwaysFalseConditionsAnalyzerTests { + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterIsNullable_NoDiagnostic() { string code = """ @@ -30,6 +31,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterIsNotNullable_Diagnostic() { string code = """ @@ -64,6 +66,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterAsPropertySymbolIsNotNullable_Diagnostic() { string code = """ @@ -99,6 +102,7 @@ public void Test() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterAsPropertySymbolIsNullable_NoDiagnostic() { string code = """ @@ -120,6 +124,7 @@ public void Test() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterAsReferenceObjectIsNotNullable_Diagnostic() { string code = """ @@ -163,6 +168,7 @@ public class ObjectClass await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterAsReferenceObjectIsNotNullable_WithoutEnableNullable_NoDiagnostic() { string code = """ @@ -187,6 +193,7 @@ public class ObjectClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenIsNullAssertion_ValueParameterAsReferenceObjectIsNullable_NoDiagnostic() { string code = """ @@ -213,6 +220,7 @@ public class ObjectClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedTrue_NoDiagnostic() { string code = """ @@ -232,6 +240,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedTrue_WithMessage_NoDiagnostic() { string code = """ @@ -251,6 +260,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedTrue_WithMessageFirst_NoDiagnostic() { string code = """ @@ -270,6 +280,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_Diagnostic() { string code = """ @@ -302,6 +313,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_WithMessage_Diagnostic() { string code = """ @@ -333,6 +345,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_WithMessageAndArgsAsParams_Diagnostic() { string code = """ @@ -370,6 +383,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_WithMessageFirst_Diagnostic() { string code = """ @@ -401,6 +415,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedUnknown_NoDiagnostic() { string code = """ @@ -422,6 +437,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -443,6 +459,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -464,6 +481,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedTrue_Diagnostic() { string code = """ @@ -496,6 +514,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedTrue_WithMessage_Diagnostic() { string code = """ @@ -528,6 +547,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedTrue_WithMessageFirst_Diagnostic() { string code = """ @@ -560,6 +580,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedFalse_NoDiagnostic() { string code = """ @@ -579,6 +600,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedFalse_WithMessage_NoDiagnostic() { string code = """ @@ -598,6 +620,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedFalse_WithMessageFirst_NoDiagnostic() { string code = """ @@ -617,6 +640,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedUnknown_NoDiagnostic() { string code = """ @@ -638,6 +662,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -659,6 +684,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -680,6 +706,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNotNullIsPassedNull_Diagnostic() { string code = """ @@ -712,6 +739,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsNotNullIsPassedNull_WithMessage_Diagnostic() { string code = """ @@ -744,6 +772,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsNotNullIsPassedNull_WithMessageFirst_Diagnostic() { string code = """ @@ -776,6 +805,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertIsNotNullIsPassedUnknown_NoDiagnostic() { string code = """ @@ -797,6 +827,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNotNullIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -818,6 +849,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNotNullIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -839,6 +871,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_NoDiagnostic() { string code = """ @@ -858,6 +891,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_WithMessage_NoDiagnostic() { string code = """ @@ -877,6 +911,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_WithMessageFirst_NoDiagnostic() { string code = """ @@ -896,6 +931,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_WithMessageSecond_NoDiagnostic() { string code = """ @@ -915,6 +951,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_Diagnostic() { string code = """ @@ -947,6 +984,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_WithMessage_Diagnostic() { string code = """ @@ -979,6 +1017,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_WithMessageFirst_Diagnostic() { string code = """ @@ -1011,6 +1050,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_WithMessageSecond_Diagnostic() { string code = """ @@ -1043,6 +1083,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_NoDiagnostic() { string code = """ @@ -1064,6 +1105,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -1085,6 +1127,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -1106,6 +1149,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_WithMessageSecond_NoDiagnostic() { string code = """ @@ -1127,6 +1171,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_Diagnostic() { string code = """ @@ -1159,6 +1204,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_WithMessage_Diagnostic() { string code = """ @@ -1191,6 +1237,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_WithMessageFirst_Diagnostic() { string code = """ @@ -1223,6 +1270,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_WithMessageSecond_Diagnostic() { string code = """ @@ -1255,6 +1303,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_NoDiagnostic() { string code = """ @@ -1274,6 +1323,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_WithMessage_NoDiagnostic() { string code = """ @@ -1293,6 +1343,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_WithMessageFirst_NoDiagnostic() { string code = """ @@ -1312,6 +1363,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_WithMessageSecond_NoDiagnostic() { string code = """ @@ -1331,6 +1383,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_NoDiagnostic() { string code = """ @@ -1352,6 +1405,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -1373,6 +1427,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -1394,6 +1449,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_WithMessageSecond_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferConstructorOverTestInitializeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferConstructorOverTestInitializeAnalyzerTests.cs index 4bead3d728..f6335eedb7 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferConstructorOverTestInitializeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferConstructorOverTestInitializeAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class PreferConstructorOverTestInitializeAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PreferConstructorOverTestInitializeAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasCtor_NoDiagnostic() { string code = """ @@ -27,6 +28,7 @@ public MyTestClass() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestClassHasTestInitialize_Diagnostic() { string code = """ @@ -56,6 +58,7 @@ public MyTestClass() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestInitializeAsync_NoDiagnostic() { string code = """ @@ -76,6 +79,7 @@ public Task MyTestInit() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestClassHasTestInitializeAndCtor_Diagnostic() { string code = """ @@ -110,6 +114,7 @@ public MyTestClass() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestInitializeAndCtorWithBody_Diagnostic() { string code = """ @@ -150,6 +155,7 @@ public MyTestClass() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestInitializeAndCtorWithBothHavingBody_Diagnostic() { string code = """ @@ -196,6 +202,7 @@ public MyTestClass() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestInitializeAndTwoCtor_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferDisposeOverTestCleanupAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferDisposeOverTestCleanupAnalyzerTests.cs index 4c93ee48f4..65bb4d83c5 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferDisposeOverTestCleanupAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferDisposeOverTestCleanupAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class PreferDisposeOverTestCleanupAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PreferDisposeOverTestCleanupAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasDispose_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public void Dispose() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestClassHasDisposeAsync_NoDiagnostic() { string code = """ @@ -48,6 +50,7 @@ public ValueTask DisposeAsync() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestClassHasTestCleanup_Diagnostic() { string code = """ @@ -79,6 +82,7 @@ public void Dispose() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestCleanup_WithAnotherBaseClass_Diagnostic() { string code = """ @@ -113,6 +117,7 @@ public void Dispose() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestCleanup_AndHasDispose_Diagnostic() { string code = """ @@ -151,6 +156,7 @@ public void Dispose() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestCleanup_AndHasDisposeInAnotherPartial_Diagnostic() { // This scenario is currently broken. The test is to document the current behavior @@ -201,6 +207,7 @@ public partial class MyTestClass : IDisposable await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestCleanupTask_Diagnostic() { string code = """ @@ -223,6 +230,7 @@ public class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestClassHasTestCleanupValueTask_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs index 278c0a417f..6681623645 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class PreferTestCleanupOverDisposeAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PreferTestCleanupOverDisposeAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasDispose_Diagnostic() { string code = """ @@ -49,6 +50,7 @@ public interface IMyInterface { } await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasDisposeAsync_Diagnostic() { string code = """ @@ -84,6 +86,7 @@ public ValueTask TestCleanup() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasTestCleanup_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestInitializeOverConstructorAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestInitializeOverConstructorAnalyzerTests.cs index 2b033a31e9..ed62792b41 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestInitializeOverConstructorAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestInitializeOverConstructorAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class PreferTestInitializeOverConstructorAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PreferTestInitializeOverConstructorAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasCtor_Diagnostic() { string code = """ @@ -39,6 +40,7 @@ public void TestInitialize() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHas_TwoCtorandExsitesTestInitialize_Diagnostic() { string code = """ @@ -97,6 +99,7 @@ public MyTestClass(int i) await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClass_WithLocalTestInitializeAttribute_Diagnostic() { string code = """ @@ -151,6 +154,7 @@ public void TestInitialize() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestClassHasImplicitCtor_NoDiagnostic() { string code = """ @@ -165,6 +169,7 @@ public class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestClassHasParameterizedCtor_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/Program.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/Program.cs index 040e4af637..f5a6c5807a 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/Program.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/Program.cs @@ -1,15 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Diagnostics; +using System.Reflection; using Microsoft.Testing.Extensions; -using Microsoft.Testing.Internal.Framework.Configurations; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] // DebuggerUtility.AttachVSToCurrentProcess(); ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new TestFrameworkConfiguration(Debugger.IsAttached ? 1 : Environment.ProcessorCount), new MSTest.Analyzers.UnitTests.SourceGeneratedTestNodesBuilder()); +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); #endif diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/Properties/launchSettings.json b/test/UnitTests/MSTest.Analyzers.UnitTests/Properties/launchSettings.json index d7b9c2736a..485ee85ee1 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/Properties/launchSettings.json +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "MSTest.Analyzers.UnitTests": { "commandName": "Project", - "commandLineArgs": "--treenode-filter /*/*/*/**" + "commandLineArgs": "" } } } diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs index da6fa23d27..2a7548dbdd 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class PublicMethodShouldBeTestMethodAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PublicMethodShouldBeTestMethodAnalyzerTests { + [TestMethod] public async Task WhenMethodIsPrivate_NoDiagnostic() { string code = """ @@ -27,6 +28,7 @@ private void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPublicButWithInvalidTestMethodSignature_NoDiagnostic() { string code = """ @@ -44,6 +46,7 @@ public static void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPublicAndMarkedAsTestMethod_NoDiagnostic() { string code = """ @@ -62,6 +65,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPrivateButNotInsideTestClass_NoDiagnostic() { string code = """ @@ -78,6 +82,7 @@ private void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPublicAndMarkedAsDerivedTestMethodAttribute_NoDiagnostic() { string code = """ @@ -99,6 +104,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPublicAndNotMarkedAsTestMethodWithInheritanceFromBaseTestClass_NoDiagnostic() { string code = """ @@ -120,6 +126,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPrivateAndNotMarkedAsTestMethodWithInheritedTestClassAttribute_NoDiagnostic() { string code = """ @@ -141,6 +148,7 @@ private void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPublicAndNotMarkedAsTestMethod_Diagnostic() { string code = """ @@ -171,6 +179,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenMethodIsPublicAndNotMarkedAsTestMethodWithInheritedTestClassAttribute_Diagnostic() { string code = """ @@ -208,6 +217,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenMethodIsPublicAndMarkedAsTestInitialize_NoDiagnostic() { string code = """ @@ -225,6 +235,7 @@ public void TestInitialize() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PublicTypeShouldBeTestClassAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PublicTypeShouldBeTestClassAnalyzerTests.cs index f9d13370ab..5aa41648b9 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PublicTypeShouldBeTestClassAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PublicTypeShouldBeTestClassAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.UnitTests; -[TestGroup] -public sealed class PublicTypeShouldBeTestClassAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class PublicTypeShouldBeTestClassAnalyzerTests { + [TestMethod] public async Task WhenClassIsPublicAndNotTestClass_Diagnostic() { string code = """ @@ -34,6 +35,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsPublicAndNotTestClassAndHaveAnotherAttribute_Diagnostic() { string code = """ @@ -60,6 +62,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsPublicAndNotClass_NoDiagnostic() { string code = """ @@ -79,6 +82,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassIsPublicAndAbstract_NoDiagnostic() { string code = """ @@ -94,6 +98,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenClassIsPublicAndStatic_NoDiagnostic() { string code = """ @@ -109,6 +114,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenTypeIsNotPublicAndNotTestClass_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/ReviewAlwaysTrueAssertConditionAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/ReviewAlwaysTrueAssertConditionAnalyzerTests.cs index 3116986593..a4d68420e0 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/ReviewAlwaysTrueAssertConditionAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/ReviewAlwaysTrueAssertConditionAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class ReviewAlwaysTrueAssertConditionAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class ReviewAlwaysTrueAssertConditionAnalyzerTests { + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterIsNotNullable_NoDiagnostic() { string code = """ @@ -30,6 +31,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterIsNotNullable_Diagnostic() { string code = """ @@ -50,6 +52,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterAsPropertySymbolIsNotNullable_Diagnostic() { string code = """ @@ -71,6 +74,7 @@ public void Test() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterAsPropertySymbolIsNullable_NoDiagnostic() { string code = """ @@ -92,6 +96,7 @@ public void Test() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterAsReferenceObjectIsNotNullable_Diagnostic() { string code = """ @@ -117,6 +122,7 @@ public class ObjectClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterAsReferenceObjectIsNotNullable_WithoutEnableNullable_NoDiagnostic() { string code = """ @@ -141,6 +147,7 @@ public class ObjectClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenIsNotNullAssertion_ValueParameterAsReferenceObjectIsNotNullable_NoDiagnostic() { string code = """ @@ -167,6 +174,7 @@ public class ObjectClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedTrue_NoDiagnostic() { string code = """ @@ -186,6 +194,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedTrue_WithMessage_NoDiagnostic() { string code = """ @@ -205,6 +214,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedTrue_WithMessageFirst_NoDiagnostic() { string code = """ @@ -224,6 +234,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedFalse_Diagnostic() { string code = """ @@ -243,6 +254,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedFalse_WithMessage_Diagnostic() { string code = """ @@ -262,6 +274,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedFalse_WithMessageFirst_Diagnostic() { string code = """ @@ -281,6 +294,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedUnknown_NoDiagnostic() { string code = """ @@ -302,6 +316,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -323,6 +338,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsFalseIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -344,6 +360,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedTrue_Diagnostic() { string code = """ @@ -363,6 +380,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedTrue_WithMessage_Diagnostic() { string code = """ @@ -382,6 +400,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedTrue_WithMessageFirst_Diagnostic() { string code = """ @@ -401,6 +420,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_NoDiagnostic() { string code = """ @@ -420,6 +440,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_WithMessage_NoDiagnostic() { string code = """ @@ -439,6 +460,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedFalse_WithMessageFirst_NoDiagnostic() { string code = """ @@ -458,6 +480,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedUnknown_NoDiagnostic() { string code = """ @@ -479,6 +502,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -500,6 +524,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsTrueIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -521,6 +546,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNullIsPassedNull_Diagnostic() { string code = """ @@ -540,6 +566,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNullIsPassedNull_WithMessage_Diagnostic() { string code = """ @@ -559,6 +586,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNullIsPassedNull_WithMessageFirst_Diagnostic() { string code = """ @@ -578,6 +606,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNullIsPassedUnknown_NoDiagnostic() { string code = """ @@ -599,6 +628,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNullIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -620,6 +650,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertIsNullIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -641,6 +672,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_NoDiagnostic() { string code = """ @@ -660,6 +692,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_WithMessage_NoDiagnostic() { string code = """ @@ -679,6 +712,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_WithMessageFirst_NoDiagnostic() { string code = """ @@ -698,6 +732,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedEqual_WithMessageSecond_NoDiagnostic() { string code = """ @@ -717,6 +752,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_Diagnostic() { string code = """ @@ -736,6 +772,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_WithMessage_Diagnostic() { string code = """ @@ -755,6 +792,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_WithMessageFirst_Diagnostic() { string code = """ @@ -774,6 +812,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedNonEqual_WithMessageSecond_Diagnostic() { string code = """ @@ -793,6 +832,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_NoDiagnostic() { string code = """ @@ -814,6 +854,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -835,6 +876,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -856,6 +898,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreNotEqualIsPassedUnknown_WithMessageSecond_NoDiagnostic() { string code = """ @@ -877,6 +920,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_Diagnostic() { string code = """ @@ -896,6 +940,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_WithMessage_Diagnostic() { string code = """ @@ -915,6 +960,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_WithMessageFirst_Diagnostic() { string code = """ @@ -934,6 +980,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedEqual_WithMessageSecond_Diagnostic() { string code = """ @@ -953,6 +1000,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_NoDiagnostic() { string code = """ @@ -972,6 +1020,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_WithMessage_NoDiagnostic() { string code = """ @@ -991,6 +1040,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_WithMessageFirst_NoDiagnostic() { string code = """ @@ -1010,6 +1060,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedNonEqual_WithMessageSecond_NoDiagnostic() { string code = """ @@ -1029,6 +1080,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_NoDiagnostic() { string code = """ @@ -1050,6 +1102,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_WithMessage_NoDiagnostic() { string code = """ @@ -1071,6 +1124,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_WithMessageFirst_NoDiagnostic() { string code = """ @@ -1092,6 +1146,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenAssertAreEqualIsPassedUnknown_WithMessageSecond_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldBeValidAnalyzerTests.cs index 6e10dd3640..b4b74c293a 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestClassShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestClassShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenClassIsPublicAndTestClass_NoDiagnostic() { string code = """ @@ -24,6 +25,7 @@ public class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenClassIsInternalAndTestClass_Diagnostic() { string code = """ @@ -52,8 +54,9 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("private")] - [Arguments("internal")] + [DataRow("private")] + [DataRow("internal")] + [TestMethod] public async Task WhenClassIsInnerAndNotPublicTestClass_Diagnostic(string accessibility) { string code = $$""" @@ -88,6 +91,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsInternalAndNotTestClass_NoDiagnostic() { string code = """ @@ -101,6 +105,7 @@ internal class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenClassIsPublicAndTestClassAsInnerOfInternalClass_Diagnostic() { string code = """ @@ -122,6 +127,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("MyTestClass")); } + [TestMethod] public async Task WhenClassIsGeneric_NoDiagnostic() { string code = """ @@ -136,6 +142,7 @@ public class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenDiscoverInternalsAndTypeIsInternal_NoDiagnostic() { string code = """ @@ -152,6 +159,7 @@ internal class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenDiscoverInternalsAndTypeIsPrivate_Diagnostic() { string code = """ @@ -190,6 +198,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsStaticAndEmpty_NoDiagnostic() { string code = """ @@ -204,6 +213,7 @@ public static class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenClassIsStaticAndContainsAssemblyInitialize_NoDiagnostic() { string code = """ @@ -222,6 +232,7 @@ public static void AssemblyInit(TestContext context) await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenClassIsStaticAndContainsAssemblyCleanup_NoDiagnostic() { string code = """ @@ -240,6 +251,7 @@ public static void AssemblyCleanup() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenClassIsStaticAndContainsClassInitialize_Diagnostic() { string code = """ @@ -276,6 +288,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsStaticAndContainsClassCleanup_Diagnostic() { string code = """ @@ -310,6 +323,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsStaticAndContainsTestInitialize_Diagnostic() { string code = """ @@ -345,6 +359,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsStaticAndContainsTestCleanup_Diagnostic() { string code = """ @@ -380,6 +395,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenClassIsStaticAndContainsTestMethod_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs index 495665896d..46bff4564b 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestClassShouldHaveTestMethodAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestClassShouldHaveTestMethodAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestClassShouldHaveTestMethodAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasTestMethod_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenStaticTestClassWithAssemblyCleanup_DoesNotHaveTestMethod_NoDiagnostic() { string code = """ @@ -46,6 +48,7 @@ public static void AssemblyCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenStaticTestClassWithAssemblyInitialization_DoesNotHaveTestMethod_NoDiagnostic() { string code = """ @@ -64,6 +67,7 @@ public static void AssemblyInitialize(TestContext context) await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassDoesNotHaveTestMethod_Diagnostic() { string code = """ @@ -82,6 +86,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("MyTestClass")); } + [TestMethod] public async Task WhenStaticTestClassWithoutAssemblyAttributes_DoesNotHaveTestMethod_Diagnostic() { string code = """ @@ -99,6 +104,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("MyTestClass")); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromAbstractClassHasTestMethod_NoDiagnostic() { string code = """ @@ -118,6 +124,7 @@ public class Derived : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromClassHasTestMethod_NoDiagnostic() { string code = """ @@ -137,6 +144,7 @@ public class Derived : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromTestClassHasTestMethod_NoDiagnostic() { string code = """ @@ -157,6 +165,7 @@ public class Derived : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromAbstractTestClassHasTestMethod_NoDiagnostic() { string code = """ @@ -177,6 +186,7 @@ public class Derived : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromBaseBaseClassHasTestMethod_NoDiagnostic() { string code = """ @@ -200,6 +210,7 @@ public class Derived : BaseClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromClassDoesNotHaveTestMethod_Diagnostic() { string code = """ @@ -221,6 +232,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("Derived")); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromClassHasAssemblyInitialize_Diagnostic() { string code = """ @@ -246,6 +258,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("Derived")); } + [TestMethod] public async Task WhenTestClassWithoutAssemblyAttributesAndTestMethod_InheritsFromBaseBaseClassHasAssemblyCleanup_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestCleanupShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestCleanupShouldBeValidAnalyzerTests.cs index b30e073f5a..cdfea41d81 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestCleanupShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestCleanupShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestCleanupShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestCleanupShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenTestCleanupIsPublic_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public void TestCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestCleanupIsPublic_InsideInternalClassWithDiscoverInternals_NoDiagnostic() { string code = """ @@ -48,6 +50,7 @@ public void TestCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestCleanupIsInternal_InsidePublicClassWithDiscoverInternals_Diagnostic() { string code = """ @@ -88,10 +91,11 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenTestCleanupIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -128,6 +132,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupIsNotOrdinary_Diagnostic() { string code = """ @@ -149,6 +154,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenTestCleanupIsAbstract_Diagnostic() { string code = """ @@ -181,6 +187,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupIsGeneric_Diagnostic() { string code = """ @@ -215,6 +222,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupIsStatic_Diagnostic() { string code = """ @@ -249,6 +257,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupHasParameters_Diagnostic() { string code = """ @@ -283,6 +292,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -358,6 +368,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -389,6 +400,7 @@ public ValueTask TestCleanup2() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestCleanupIsAsyncVoid_Diagnostic() { string code = """ @@ -427,6 +439,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenMultipleViolations_TheyAllGetFixed() { string code = """ @@ -465,6 +478,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestCleanupIsNotOnClass_Diagnostic() { string code = """ @@ -482,6 +496,7 @@ public struct MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestCleanupIsOnSealedClassNotMarkedWithTestClass_Diagnostic() { string code = """ @@ -499,6 +514,7 @@ public sealed class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestCleanupIsOnNonSealedClassNotMarkedWithTestClass_NoDiagnostic() { string code = """ @@ -516,6 +532,7 @@ public void TestCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestCleanupIsOnGenericClass_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestContextShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestContextShouldBeValidAnalyzerTests.cs index 141b0f0202..e2965c8523 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestContextShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestContextShouldBeValidAnalyzerTests.cs @@ -7,25 +7,26 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestContextShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestContextShouldBeValidAnalyzerTests { - [Arguments("TestContext", "private")] - [Arguments("TestContext", "public")] - [Arguments("TestContext", "internal")] - [Arguments("TestContext", "protected")] - [Arguments("testcontext", "private")] - [Arguments("testcontext", "public")] - [Arguments("testcontext", "internal")] - [Arguments("testcontext", "protected")] - [Arguments("TESTCONTEXT", "private")] - [Arguments("TESTCONTEXT", "public")] - [Arguments("TESTCONTEXT", "internal")] - [Arguments("TESTCONTEXT", "protected")] - [Arguments("TeStCoNtExT", "private")] - [Arguments("TeStCoNtExT", "public")] - [Arguments("TeStCoNtExT", "internal")] - [Arguments("TeStCoNtExT", "protected")] + [DataRow("TestContext", "private")] + [DataRow("TestContext", "public")] + [DataRow("TestContext", "internal")] + [DataRow("TestContext", "protected")] + [DataRow("testcontext", "private")] + [DataRow("testcontext", "public")] + [DataRow("testcontext", "internal")] + [DataRow("testcontext", "protected")] + [DataRow("TESTCONTEXT", "private")] + [DataRow("TESTCONTEXT", "public")] + [DataRow("TESTCONTEXT", "internal")] + [DataRow("TESTCONTEXT", "protected")] + [DataRow("TeStCoNtExT", "private")] + [DataRow("TeStCoNtExT", "public")] + [DataRow("TeStCoNtExT", "internal")] + [DataRow("TeStCoNtExT", "protected")] + [TestMethod] public async Task WhenTestContextCaseInsensitiveIsField_Diagnostic(string fieldName, string accessibility) { string code = $$""" @@ -52,22 +53,23 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("TestContext", "private")] - [Arguments("TestContext", "public")] - [Arguments("TestContext", "internal")] - [Arguments("TestContext", "protected")] - [Arguments("testcontext", "private")] - [Arguments("testcontext", "public")] - [Arguments("testcontext", "internal")] - [Arguments("testcontext", "protected")] - [Arguments("TESTCONTEXT", "private")] - [Arguments("TESTCONTEXT", "public")] - [Arguments("TESTCONTEXT", "internal")] - [Arguments("TESTCONTEXT", "protected")] - [Arguments("TeStCoNtExT", "private")] - [Arguments("TeStCoNtExT", "public")] - [Arguments("TeStCoNtExT", "internal")] - [Arguments("TeStCoNtExT", "protected")] + [DataRow("TestContext", "private")] + [DataRow("TestContext", "public")] + [DataRow("TestContext", "internal")] + [DataRow("TestContext", "protected")] + [DataRow("testcontext", "private")] + [DataRow("testcontext", "public")] + [DataRow("testcontext", "internal")] + [DataRow("testcontext", "protected")] + [DataRow("TESTCONTEXT", "private")] + [DataRow("TESTCONTEXT", "public")] + [DataRow("TESTCONTEXT", "internal")] + [DataRow("TESTCONTEXT", "protected")] + [DataRow("TeStCoNtExT", "private")] + [DataRow("TeStCoNtExT", "public")] + [DataRow("TeStCoNtExT", "internal")] + [DataRow("TeStCoNtExT", "protected")] + [TestMethod] public async Task WhenTestContextCaseInsensitiveIsField_AssignedInConstructor_NoDiagnostic(string fieldName, string accessibility) { string code = $$""" @@ -88,14 +90,15 @@ public MyTestClass(TestContext testContext) await VerifyCS.VerifyCodeFixAsync(code, code); } - [Arguments("TestContext", "private")] - [Arguments("TestContext", "internal")] - [Arguments("testcontext", "private")] - [Arguments("testcontext", "internal")] - [Arguments("TESTCONTEXT", "private")] - [Arguments("TESTCONTEXT", "internal")] - [Arguments("TeStCoNtExT", "private")] - [Arguments("TeStCoNtExT", "internal")] + [DataRow("TestContext", "private")] + [DataRow("TestContext", "internal")] + [DataRow("testcontext", "private")] + [DataRow("testcontext", "internal")] + [DataRow("TESTCONTEXT", "private")] + [DataRow("TESTCONTEXT", "internal")] + [DataRow("TeStCoNtExT", "private")] + [DataRow("TeStCoNtExT", "internal")] + [TestMethod] public async Task WhenTestContextPropertyIsPrivateOrInternal_Diagnostic(string propertyName, string accessibility) { string code = $$""" @@ -123,14 +126,15 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("TestContext", "private")] - [Arguments("TestContext", "internal")] - [Arguments("testcontext", "private")] - [Arguments("testcontext", "internal")] - [Arguments("TESTCONTEXT", "private")] - [Arguments("TESTCONTEXT", "internal")] - [Arguments("TeStCoNtExT", "private")] - [Arguments("TeStCoNtExT", "internal")] + [DataRow("TestContext", "private")] + [DataRow("TestContext", "internal")] + [DataRow("testcontext", "private")] + [DataRow("testcontext", "internal")] + [DataRow("TESTCONTEXT", "private")] + [DataRow("TESTCONTEXT", "internal")] + [DataRow("TeStCoNtExT", "private")] + [DataRow("TeStCoNtExT", "internal")] + [TestMethod] public async Task WhenTestContextPropertyIsPrivateOrInternal_AssignedInConstructor_NoDiagnostic(string propertyName, string accessibility) { string code = $$""" @@ -151,8 +155,9 @@ public MyTestClass(TestContext testContext) await VerifyCS.VerifyCodeFixAsync(code, code); } - [Arguments(true)] - [Arguments(false)] + [DataRow(true)] + [DataRow(false)] + [TestMethod] public async Task WhenTestContextPropertyIsValid_NoDiagnostic(bool discoverInternals) { string code = $$""" @@ -170,6 +175,7 @@ public class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenDiscoverInternalsTestContextPropertyIsPrivate_Diagnostic() { string code = """ @@ -202,6 +208,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenDiscoverInternalsTestContextPropertyIsPrivate_AssignedInConstructor_NoDiagnostic() { string code = """ @@ -224,6 +231,7 @@ public MyTestClass(TestContext testContext) await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenDiscoverInternalsTestContextPropertyIsInternal_Diagnostic() { string code = """ @@ -253,6 +261,7 @@ public class MyTestClass await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenDiscoverInternalsTestContextPropertyIsInternal_AssignedInConstructor_NoDiagnostic() { string code = """ @@ -275,6 +284,7 @@ public MyTestClass(TestContext testContext) await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestContextPropertyIsStatic_Diagnostic() { string code = $$""" @@ -303,6 +313,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestContextPropertyIsReadonly_Diagnostic() { string code = $$""" @@ -331,6 +342,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestContextPropertyIsReadonly_AssignedInConstructor_NoDiagnostic() { string code = $$""" @@ -351,22 +363,23 @@ public MyTestClass(TestContext testContext) await VerifyCS.VerifyCodeFixAsync(code, code); } - [Arguments("TestContext", "private")] - [Arguments("TestContext", "public")] - [Arguments("TestContext", "internal")] - [Arguments("TestContext", "protected")] - [Arguments("testcontext", "private")] - [Arguments("testcontext", "public")] - [Arguments("testcontext", "internal")] - [Arguments("testcontext", "protected")] - [Arguments("TESTCONTEXT", "private")] - [Arguments("TESTCONTEXT", "public")] - [Arguments("TESTCONTEXT", "internal")] - [Arguments("TESTCONTEXT", "protected")] - [Arguments("TeStCoNtExT", "private")] - [Arguments("TeStCoNtExT", "public")] - [Arguments("TeStCoNtExT", "internal")] - [Arguments("TeStCoNtExT", "protected")] + [DataRow("TestContext", "private")] + [DataRow("TestContext", "public")] + [DataRow("TestContext", "internal")] + [DataRow("TestContext", "protected")] + [DataRow("testcontext", "private")] + [DataRow("testcontext", "public")] + [DataRow("testcontext", "internal")] + [DataRow("testcontext", "protected")] + [DataRow("TESTCONTEXT", "private")] + [DataRow("TESTCONTEXT", "public")] + [DataRow("TESTCONTEXT", "internal")] + [DataRow("TESTCONTEXT", "protected")] + [DataRow("TeStCoNtExT", "private")] + [DataRow("TeStCoNtExT", "public")] + [DataRow("TeStCoNtExT", "internal")] + [DataRow("TeStCoNtExT", "protected")] + [TestMethod] public async Task WhenTestContextIsFieldNotOnTestClass_NoDiagnostic(string fieldName, string accessibility) { string code = $$""" diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestInitializeShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestInitializeShouldBeValidAnalyzerTests.cs index e46e21c15e..d8eb9cbe5e 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestInitializeShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestInitializeShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestInitializeShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestInitializeShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenTestInitializeIsPublic_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public void TestInitialize() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestInitializeIsNotOrdinary_Diagnostic() { string code = """ @@ -49,6 +51,7 @@ await VerifyCS.VerifyCodeFixAsync( code); } + [TestMethod] public async Task WhenTestInitializeIsPublic_InsideInternalClassWithDiscoverInternals_NoDiagnostic() { string code = """ @@ -69,6 +72,7 @@ public void TestInitialize() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestInitializeIsInternal_InsidePublicClassWithDiscoverInternals_Diagnostic() { string code = """ @@ -107,10 +111,11 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenTestInitializeIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -147,6 +152,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeIsAbstract_Diagnostic() { string code = """ @@ -179,6 +185,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeIsGeneric_Diagnostic() { string code = """ @@ -213,6 +220,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeIsStatic_Diagnostic() { string code = """ @@ -247,6 +255,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeHasParameters_Diagnostic() { string code = """ @@ -281,6 +290,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -356,6 +366,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -387,6 +398,7 @@ public ValueTask TestInitialize2() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestInitializeIsAsyncVoid_Diagnostic() { string code = """ @@ -425,6 +437,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenMultipleViolations_TheyAllGetFixed() { string code = """ @@ -463,6 +476,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenTestInitializeIsNotOnClass_Diagnostic() { string code = """ @@ -480,6 +494,7 @@ public struct MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestInitializeIsOnSealedClassNotMarkedWithTestClass_Diagnostic() { string code = """ @@ -497,6 +512,7 @@ public sealed class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestInitializeIsOnNonSealedClassNotMarkedWithTestClass_NoDiagnostic() { string code = """ @@ -514,6 +530,7 @@ public void TestInitialize() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestInitializeIsOnGenericClass_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldBeValidAnalyzerTests.cs index 714c32714f..77323cb892 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldBeValidAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestMethodShouldBeValidAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestMethodShouldBeValidAnalyzerTests { + [TestMethod] public async Task WhenTestMethodIsPublic_NoDiagnostic() { string code = """ @@ -28,10 +29,11 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } - [Arguments("protected")] - [Arguments("internal")] - [Arguments("internal protected")] - [Arguments("private")] + [DataRow("protected")] + [DataRow("internal")] + [DataRow("internal protected")] + [DataRow("private")] + [TestMethod] public async Task WhenTestMethodIsNotPublic_Diagnostic(string accessibility) { string code = $$""" @@ -63,6 +65,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenMethodIsNotPublicAndNotTestMethod_NoDiagnostic() { string code = $$""" @@ -92,6 +95,7 @@ internal void InternalMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestMethodIsStatic_Diagnostic() { string code = """ @@ -123,6 +127,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestMethodIsAbstract_Diagnostic() { string code = """ @@ -152,6 +157,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestMethodIsGeneric_Diagnostic() { string code = """ @@ -195,6 +201,7 @@ public void MyTestMethod(T t) await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestMethodIsNotOrdinary_Diagnostic() { string code = """ @@ -213,6 +220,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestMethodReturnTypeIsNotValid_Diagnostic() { string code = """ @@ -280,6 +288,7 @@ public void MyTestMethod3() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestMethodReturnTypeIsValid_NoDiagnostic() { string code = """ @@ -311,6 +320,7 @@ public ValueTask MyTestMethod2() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestMethodIsAsyncVoid_Diagnostic() { string code = """ @@ -344,6 +354,7 @@ public async Task MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, fixedCode); } + [TestMethod] public async Task WhenTestMethodIsInternalAndDiscoverInternals_NoDiagnostic() { string code = """ @@ -383,6 +394,7 @@ public void MyTestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } + [TestMethod] public async Task WhenTestMethodIsPrivateAndDiscoverInternals_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs index 7deb038f4a..9c66e4a8f0 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TestMethodShouldNotBeIgnoredAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TestMethodShouldNotBeIgnoredAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TestMethodShouldNotBeIgnoredAnalyzerTests { + [TestMethod] public async Task WhenTestMethodIsNotIgnored_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingIgnoreWithoutTestMethod_NoDiagnostic() { string code = """ @@ -46,6 +48,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestMethodIsIgnored_Diagnostic() { string code = """ @@ -69,6 +72,7 @@ await VerifyCS.VerifyAnalyzerAsync( .WithArguments("MyTestMethod")); } + [TestMethod] public async Task WhenDerivedTestMethodAttributeIsIgnored_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/TypeContainingTestMethodShouldBeATestClassAnalyzer.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/TypeContainingTestMethodShouldBeATestClassAnalyzer.cs index a743894786..816b3d6653 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/TypeContainingTestMethodShouldBeATestClassAnalyzer.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/TypeContainingTestMethodShouldBeATestClassAnalyzer.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class TypeContainingTestMethodShouldBeATestClassAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TypeContainingTestMethodShouldBeATestClassAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasTestMethod_NoDiagnostic() { string code = """ @@ -28,6 +29,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassWithoutTestAttribute_HaveTestMethod_Diagnostic() { string code = """ @@ -43,6 +45,7 @@ public void TestMethod1() {} await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassWithoutTestAttribute_AndWithoutTestMethods_InheritTestClassWithTestMethods_Diagnostic() { string code = """ @@ -71,6 +74,7 @@ public void TestMethod2() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassWithoutTestAttribute_AndWithTestMethods_InheritTestClass_Diagnostic() { string code = """ @@ -99,6 +103,7 @@ public void TestMethod2() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenInheritedTestClassAttribute_HasInheritedTestMethodAttribute_NoDiagnostic() { string code = """ @@ -125,6 +130,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassWithoutTestAttribute_HasInheritedTestMethodAttribute_Diagnostic() { string code = """ @@ -146,6 +152,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAbstractClassWithoutTestAttribute_HaveTestMethod_NoDiagnostic() { string code = """ @@ -163,6 +170,7 @@ public void TestMethod1() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenClassHasTestInitializeAndThenTestMethod_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestFixtureMethodSuppressorTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestFixtureMethodSuppressorTests.cs index c9a55fb143..e55bdf9e1a 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestFixtureMethodSuppressorTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestFixtureMethodSuppressorTests.cs @@ -13,9 +13,10 @@ namespace MSTest.Analyzers.UnitTests; -[TestGroup] -public sealed class UseAsyncSuffixTestFixtureMethodSuppressorTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class UseAsyncSuffixTestFixtureMethodSuppressorTests { + [TestMethod] public async Task AsyncTestFixtureMethodsWithoutSuffix_DiagnosticIsSuppressed() { string code = @" @@ -57,6 +58,7 @@ public class SomeClass }.RunAsync(); } + [TestMethod] public async Task AsyncTestMethodWithSuffix_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestMethodSuppressorTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestMethodSuppressorTests.cs index de624c2e06..f5bced8a52 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestMethodSuppressorTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAsyncSuffixTestMethodSuppressorTests.cs @@ -13,9 +13,10 @@ namespace MSTest.Analyzers.UnitTests; -[TestGroup] -public sealed class UseAsyncSuffixTestMethodSuppressorTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class UseAsyncSuffixTestMethodSuppressorTests { + [TestMethod] public async Task AsyncTestMethodWithoutSuffix_DiagnosticIsSuppressed() { string code = @@ -45,6 +46,7 @@ public class SomeClass }.RunAsync(); } + [TestMethod] public async Task AsyncDataTestMethodWithoutSuffix_DiagnosticIsSuppressed() { string code = @@ -73,6 +75,7 @@ public class SomeClass }.RunAsync(); } + [TestMethod] public async Task AsyncTestMethodWithSuffix_NoDiagnostic() { string code = diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs index 17f3b8a420..f7353183ad 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs @@ -9,8 +9,8 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class UseAttributeOnTestMethodAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class UseAttributeOnTestMethodAnalyzerTests { private static readonly List<(DiagnosticDescriptor Rule, string AttributeUsageExample)> RuleUsageExamples = [ @@ -35,11 +35,11 @@ protected override void Verify(System.Exception exception) { } internal static IEnumerable<(DiagnosticDescriptor Rule, string AttributeUsageExample)> GetAttributeUsageExampleAndRuleTuples() => RuleUsageExamples.Select(tuple => (tuple.Rule, tuple.AttributeUsageExample)); - internal static IEnumerable GetAttributeUsageExamples() - => RuleUsageExamples.Select(tuple => tuple.AttributeUsageExample); + internal static IEnumerable GetAttributeUsageExamples() + => RuleUsageExamples.Select(tuple => new object[] { tuple.AttributeUsageExample }); // This generates all possible combinations of any two tuples (Rule, AttributeUsageExample) with the exception of the - // combaination where the two tuples are equal. The result is flattened in a new tuple created from the elements of the + // combination where the two tuples are equal. The result is flattened in a new tuple created from the elements of the // previous two tuples. internal static IEnumerable<(DiagnosticDescriptor Rule1, string AttributeUsageExample1, DiagnosticDescriptor Rule2, string AttributeUsageExample2)> GetAttributeUsageExampleAndRuleTuplesForTwoAttributes() => RuleUsageExamples @@ -47,7 +47,8 @@ internal static IEnumerable GetAttributeUsageExamples() .Where(tuples => !tuples.tuple1.AttributeUsageExample.Equals(tuples.tuple2.AttributeUsageExample, StringComparison.Ordinal)) .Select(tuples => (tuples.tuple1.Rule, tuples.tuple1.AttributeUsageExample, tuples.tuple2.Rule, tuples.tuple2.AttributeUsageExample)); - [ArgumentsProvider(nameof(GetAttributeUsageExamples))] + [DynamicData(nameof(GetAttributeUsageExamples), DynamicDataSourceType.Method)] + [TestMethod] public async Task WhenMethodIsMarkedWithTestMethodAndTestAttributes_NoDiagnosticAsync(string attributeUsageExample) { string code = $$""" @@ -69,7 +70,8 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } - [ArgumentsProvider(nameof(GetAttributeUsageExampleAndRuleTuples))] + [DynamicData(nameof(GetAttributeUsageExampleAndRuleTuples), DynamicDataSourceType.Method)] + [TestMethod] public async Task WhenMethodIsMarkedWithTestAttributeButNotWithTestMethod_DiagnosticAsync(DiagnosticDescriptor rule, string attributeUsageExample) { string code = $$""" @@ -106,7 +108,8 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, VerifyCS.Diagnostic(rule).WithLocation(0), fixedCode); } - [ArgumentsProvider(nameof(GetAttributeUsageExampleAndRuleTuplesForTwoAttributes))] + [DynamicData(nameof(GetAttributeUsageExampleAndRuleTuplesForTwoAttributes), DynamicDataSourceType.Method)] + [TestMethod] public async Task WhenMethodIsMarkedWithMultipleTestAttributesButNotWithTestMethod_DiagnosticOnEachAttributeAsync( DiagnosticDescriptor rule1, string attributeUsageExample1, @@ -149,7 +152,8 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, new[] { VerifyCS.Diagnostic(rule1).WithLocation(0), VerifyCS.Diagnostic(rule2).WithLocation(1) }, fixedCode); } - [ArgumentsProvider(nameof(GetAttributeUsageExamples))] + [DynamicData(nameof(GetAttributeUsageExamples), DynamicDataSourceType.Method)] + [TestMethod] public async Task WhenMethodIsMarkedWithTestAttributeAndCustomTestMethod_NoDiagnosticAsync(string attributeUsageExample) { string code = $$""" diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseClassCleanupBehaviorEndOfClassAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseClassCleanupBehaviorEndOfClassAnalyzerTests.cs index 531bf1886c..6406ceff68 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseClassCleanupBehaviorEndOfClassAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseClassCleanupBehaviorEndOfClassAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class UseClassCleanupBehaviorEndOfClassAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class UseClassCleanupBehaviorEndOfClassAnalyzerTests { + [TestMethod] public async Task UsingClassCleanup_WithoutCleanupBehaviorEndOfClass_AndNotInsideTestClass_NoDiagnostic() { string code = """ @@ -27,6 +28,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithoutCleanupBehaviorEndOfClass_AndInsideTestClass_Diagnostic() { string code = """ @@ -45,6 +47,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithCleanupBehaviorEndOfClass_NoDiagnostic() { string code = """ @@ -63,6 +66,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithCleanupBehaviorEndOfAssembly_Diagnostic() { string code = """ @@ -81,6 +85,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithoutCleanupBehavior_Diagnostic() { string code = """ @@ -99,6 +104,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithoutCleanupBehaviorAndWithInheritanceBehavior_Diagnostic() { string code = """ @@ -117,6 +123,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithCleanupBehaviorEndOFAssemblyAndWithInheritanceBehavior_Diagnostic() { string code = """ @@ -135,6 +142,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_WithCleanupBehaviorEndOFClassAndWithInheritanceBehavior_NoDiagnostic() { string code = """ @@ -153,6 +161,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_InsideTestClass_WithClassCleanupExecutionWithEndOfClassBehavior_NoDiagnostic() { string code = """ @@ -172,6 +181,7 @@ public static void ClassCleanup() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_InsideTestClass_WithClassCleanupExecutionWithEndOfAsseblyBehavior_Diagnostic() { string code = """ @@ -191,6 +201,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_InsideTestClass_WithClassCleanupExecutionWithEndOfClassBehavior_WithCleanupBehaviorEndOfAssembly_Diagnostic() { string code = """ @@ -210,6 +221,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task UsingClassCleanup_InsideTestClass_WithClassCleanupExecutionWithEndOfAssemblyBehavior_WithCleanupBehaviorEndOfClass_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs index 228f7c2f41..ecfd32451e 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests.cs @@ -7,9 +7,10 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public sealed class UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class UseDeploymentItemWithTestMethodOrTestClassAnalyzerTests { + [TestMethod] public async Task WhenTestClassHasDeploymentItem_NoDiagnostic() { string code = """ @@ -25,6 +26,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenTestMethodHasDeploymentItem_NoDiagnostic() { string code = """ @@ -44,6 +46,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenInheritedTestClassAttributeHasDeploymentItem_NoDiagnostic() { string code = """ @@ -62,6 +65,7 @@ public class MyTestClass await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenInheritedTestMethodAttributeHasDeploymentItem_NoDiagnostic() { string code = """ @@ -84,6 +88,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAClassHasDeploymentItem_Diagnostic() { string code = """ @@ -98,6 +103,7 @@ public class [|MyTestClass|] await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAMethodHasDeploymentItem_Diagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs index ddc0b5b5b8..7dcf190ed1 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseParallelizeAttributeAnalyzerTests.cs @@ -7,13 +7,15 @@ namespace MSTest.Analyzers.Test; -[TestGroup] -public class UseParallelizeAttributeAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public class UseParallelizeAttributeAnalyzerTests { + [TestMethod] public async Task WhenNoAttributeSpecified_Diagnostic() => await VerifyCS.VerifyAnalyzerAsync( string.Empty, VerifyCS.Diagnostic(UseParallelizeAttributeAnalyzer.Rule).WithNoLocation()); + [TestMethod] public async Task WhenParallelizeAttributeSet_NoDiagnostic() { string code = """ @@ -25,6 +27,7 @@ public async Task WhenParallelizeAttributeSet_NoDiagnostic() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenDoNotParallelizeAttributeSet_NoDiagnostic() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseProperAssertMethodsAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseProperAssertMethodsAnalyzerTests.cs index 61c1187523..cdb5bfaf7c 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseProperAssertMethodsAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseProperAssertMethodsAnalyzerTests.cs @@ -8,9 +8,10 @@ namespace MSTest.Analyzers.Test; // NOTE: tests in this class are intentionally not using the [|...|] markup syntax so that we test the arguments -[TestGroup] -public sealed class UseProperAssertMethodsAnalyzerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class UseProperAssertMethodsAnalyzerTests { + [TestMethod] public async Task WhenAssertIsTrueWithEqualsNullArgument() { string code = """ @@ -50,6 +51,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueWithIsNullArgument() { string code = """ @@ -89,6 +91,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueWithNotEqualsNullArgument() { string code = """ @@ -128,6 +131,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueWithIsNotNullArgument() { string code = """ @@ -167,6 +171,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseWithEqualsNullArgument() { string code = """ @@ -206,6 +211,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseWithIsNullArgument() { string code = """ @@ -245,6 +251,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseWithNotEqualsNullArgument() { string code = """ @@ -284,6 +291,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseWithIsNotNullArgument() { string code = """ @@ -323,6 +331,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueAndArgumentIsEquality() { string code = """ @@ -364,6 +373,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsTrueAndArgumentIsInequality() { string code = """ @@ -405,6 +415,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseAndArgumentIsEquality() { string code = """ @@ -446,6 +457,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertIsFalseAndArgumentIsInequality() { string code = """ @@ -487,6 +499,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualAndExpectedIsNull() { string code = """ @@ -526,6 +539,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualAndExpectedIsNull() { string code = """ @@ -565,6 +579,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualAndExpectedIsTrue() { string code = """ @@ -604,6 +619,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualAndExpectedIsTrue_CastNotAddedWhenTypeIsBool() { string code = """ @@ -643,6 +659,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualAndExpectedIsTrue_CastNotAddedWhenTypeIsNullableBool() { string code = """ @@ -682,6 +699,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreEqualAndExpectedIsTrue_CastShouldBeAddedWithParentheses() { string code = """ @@ -731,6 +749,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualAndExpectedIsTrue() { string code = """ @@ -754,6 +773,7 @@ public void MyTestMethod() await VerifyCS.VerifyAnalyzerAsync(code); } + [TestMethod] public async Task WhenAssertAreEqualAndExpectedIsFalse() { string code = """ @@ -793,6 +813,7 @@ await VerifyCS.VerifyCodeFixAsync( fixedCode); } + [TestMethod] public async Task WhenAssertAreNotEqualAndExpectedIsFalse() { string code = """ diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs index 9db21ba08b..3fc45b7658 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs @@ -6,7 +6,6 @@ using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext; diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AppInsightsProviderTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AppInsightsProviderTests.cs index 2d025fb0ae..41643a7bf0 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AppInsightsProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AppInsightsProviderTests.cs @@ -12,14 +12,10 @@ namespace Microsoft.Testing.Extensions.UnitTests; -[TestGroup] -public sealed class AppInsightsProviderTests : TestBase +[TestClass] +public sealed class AppInsightsProviderTests { - public AppInsightsProviderTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void Platform_CancellationToken_Cancellation_Should_Exit_Gracefully() { Mock environment = new(); @@ -84,9 +80,10 @@ public void Platform_CancellationToken_Cancellation_Should_Exit_Gracefully() #endif // We expect to not consume the second event because we exit the inner loop for the cancellation token - Assert.IsTrue(events.Single() == "Sample"); + Assert.AreEqual("Sample", events.Single()); } + [TestMethod] public void Timeout_During_Dispose_Should_Exit_Gracefully() { Mock environment = new(); diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs index a858eccdf2..065485ff10 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs @@ -10,13 +10,14 @@ namespace Microsoft.Testing.Extensions.UnitTests; -[TestGroup] -public class CrashDumpTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class CrashDumpTests { - [Arguments("Mini")] - [Arguments("Heap")] - [Arguments("Triage")] - [Arguments("Full")] + [TestMethod] + [DataRow("Mini")] + [DataRow("Heap")] + [DataRow("Triage")] + [DataRow("Full")] public async Task IsValid_If_CrashDumpType_Has_CorrectValue(string crashDumpType) { var provider = new CrashDumpCommandLineProvider(); @@ -27,6 +28,7 @@ public async Task IsValid_If_CrashDumpType_Has_CorrectValue(string crashDumpType Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } + [TestMethod] public async Task IsInvValid_If_CrashDumpType_Has_IncorrectValue() { var provider = new CrashDumpCommandLineProvider(); @@ -37,6 +39,7 @@ public async Task IsInvValid_If_CrashDumpType_Has_IncorrectValue() Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, CrashDumpResources.CrashDumpTypeOptionInvalidType, "invalid"), validateOptionsResult.ErrorMessage); } + [TestMethod] public async Task CrashDump_CommandLineOptions_Are_AlwaysValid() { var provider = new CrashDumpCommandLineProvider(); diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/HangDumpTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/HangDumpTests.cs index c3c239e37f..7c78930cef 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/HangDumpTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/HangDumpTests.cs @@ -14,8 +14,8 @@ namespace Microsoft.Testing.Extensions.UnitTests; -[TestGroup] -public class HangDumpTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class HangDumpTests { private HangDumpCommandLineProvider GetProvider() { @@ -27,6 +27,7 @@ private HangDumpCommandLineProvider GetProvider() "suffix")); } + [TestMethod] public async Task IsValid_If_Timeout_Value_Has_CorrectValue() { HangDumpCommandLineProvider hangDumpCommandLineProvider = GetProvider(); @@ -37,6 +38,7 @@ public async Task IsValid_If_Timeout_Value_Has_CorrectValue() Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } + [TestMethod] public async Task IsInvalid_If_Timeout_Value_Has_IncorrectValue() { HangDumpCommandLineProvider hangDumpCommandLineProvider = GetProvider(); @@ -47,12 +49,13 @@ public async Task IsInvalid_If_Timeout_Value_Has_IncorrectValue() Assert.AreEqual(ExtensionResources.HangDumpTimeoutOptionInvalidArgument, validateOptionsResult.ErrorMessage); } + [TestMethod] #if NETCOREAPP - [Arguments("Triage")] + [DataRow("Triage")] #endif - [Arguments("Mini")] - [Arguments("Heap")] - [Arguments("Full")] + [DataRow("Mini")] + [DataRow("Heap")] + [DataRow("Full")] public async Task IsValid_If_HangDumpType_Has_CorrectValue(string dumpType) { HangDumpCommandLineProvider hangDumpCommandLineProvider = GetProvider(); @@ -63,6 +66,7 @@ public async Task IsValid_If_HangDumpType_Has_CorrectValue(string dumpType) Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } + [TestMethod] public async Task IsInvalid_If_HangDumpType_Has_IncorrectValue() { HangDumpCommandLineProvider hangDumpCommandLineProvider = GetProvider(); @@ -73,9 +77,10 @@ public async Task IsInvalid_If_HangDumpType_Has_IncorrectValue() Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, ExtensionResources.HangDumpTypeOptionInvalidType, "invalid"), validateOptionsResult.ErrorMessage); } - [Arguments(HangDumpCommandLineProvider.HangDumpFileNameOptionName)] - [Arguments(HangDumpCommandLineProvider.HangDumpTimeoutOptionName)] - [Arguments(HangDumpCommandLineProvider.HangDumpTypeOptionName)] + [TestMethod] + [DataRow(HangDumpCommandLineProvider.HangDumpFileNameOptionName)] + [DataRow(HangDumpCommandLineProvider.HangDumpTimeoutOptionName)] + [DataRow(HangDumpCommandLineProvider.HangDumpTypeOptionName)] public async Task Missing_HangDumpMainOption_ShouldReturn_IsInvalid(string hangDumpArgument) { HangDumpCommandLineProvider hangDumpCommandLineProvider = GetProvider(); @@ -86,12 +91,13 @@ public async Task Missing_HangDumpMainOption_ShouldReturn_IsInvalid(string hangD ValidationResult validateOptionsResult = await hangDumpCommandLineProvider.ValidateCommandLineOptionsAsync(new TestCommandLineOptions(options)); Assert.IsFalse(validateOptionsResult.IsValid); - Assert.AreEqual(validateOptionsResult.ErrorMessage, "You specified one or more hang dump parameters but did not enable it, add --hangdump to the command line"); + Assert.AreEqual("You specified one or more hang dump parameters but did not enable it, add --hangdump to the command line", validateOptionsResult.ErrorMessage); } - [Arguments(HangDumpCommandLineProvider.HangDumpFileNameOptionName)] - [Arguments(HangDumpCommandLineProvider.HangDumpTimeoutOptionName)] - [Arguments(HangDumpCommandLineProvider.HangDumpTypeOptionName)] + [TestMethod] + [DataRow(HangDumpCommandLineProvider.HangDumpFileNameOptionName)] + [DataRow(HangDumpCommandLineProvider.HangDumpTimeoutOptionName)] + [DataRow(HangDumpCommandLineProvider.HangDumpTypeOptionName)] public async Task If_HangDumpMainOption_IsSpecified_ShouldReturn_IsValid(string hangDumpArgument) { HangDumpCommandLineProvider hangDumpCommandLineProvider = GetProvider(); diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj index 1acf72929b..e016c30a3a 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj @@ -3,8 +3,7 @@ $(MicrosoftTestingTargetFrameworks);net462 false - Exe - true + true diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Program.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Program.cs index 637390b157..5464028d18 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Program.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Program.cs @@ -1,10 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Reflection; + using Microsoft.Testing.Extensions; +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] + ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new Microsoft.Testing.Extensions.UnitTests.SourceGeneratedTestNodesBuilder()); + +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); #endif diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Properties/launchSettings.json b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Properties/launchSettings.json index ebf3f0f011..7195225907 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Properties/launchSettings.json +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Microsoft.Testing.Extensions.UnitTests": { "commandName": "Project", - "commandLineArgs": "--treenode-filter /*/*/*/**" + "commandLineArgs": "" } } } diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxCompareToolCommandLineTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxCompareToolCommandLineTests.cs index ce0d3c10ca..e8e3005358 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxCompareToolCommandLineTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxCompareToolCommandLineTests.cs @@ -9,11 +9,12 @@ namespace Microsoft.Testing.Extensions.UnitTests; -[TestGroup] -public class TrxCompareToolCommandLineTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TrxCompareToolCommandLineTests { - [Arguments(TrxCompareToolCommandLine.BaselineTrxOptionName)] - [Arguments(TrxCompareToolCommandLine.TrxToCompareOptionName)] + [TestMethod] + [DataRow(TrxCompareToolCommandLine.BaselineTrxOptionName)] + [DataRow(TrxCompareToolCommandLine.TrxToCompareOptionName)] public async Task IsValid_When_Correct_TrxFile_IsProvided_For_Options(string optionName) { var provider = new TrxCompareToolCommandLine(new TestExtension()); @@ -27,10 +28,11 @@ public async Task IsValid_When_Correct_TrxFile_IsProvided_For_Options(string opt File.Delete(filename); } - [Arguments(TrxCompareToolCommandLine.BaselineTrxOptionName, false)] - [Arguments(TrxCompareToolCommandLine.BaselineTrxOptionName, true)] - [Arguments(TrxCompareToolCommandLine.TrxToCompareOptionName, false)] - [Arguments(TrxCompareToolCommandLine.TrxToCompareOptionName, true)] + [TestMethod] + [DataRow(TrxCompareToolCommandLine.BaselineTrxOptionName, false)] + [DataRow(TrxCompareToolCommandLine.BaselineTrxOptionName, true)] + [DataRow(TrxCompareToolCommandLine.TrxToCompareOptionName, false)] + [DataRow(TrxCompareToolCommandLine.TrxToCompareOptionName, true)] public async Task IsInvalid_When_Incorrect_TrxFile_IsProvided_For_Options(string optionName, bool isTrxFile) { var provider = new TrxCompareToolCommandLine(new TestExtension()); @@ -42,6 +44,7 @@ public async Task IsInvalid_When_Incorrect_TrxFile_IsProvided_For_Options(string Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, TestReports.Resources.ExtensionResources.TrxComparerToolOptionExpectsSingleArgument, optionName), validateOptionsResult.ErrorMessage); } + [TestMethod] public async Task IsValid_If_Both_TrxOptions_Are_Provided() { var provider = new TrxCompareToolCommandLine(new TestExtension()); @@ -56,8 +59,9 @@ public async Task IsValid_If_Both_TrxOptions_Are_Provided() Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } - [Arguments(true, false)] - [Arguments(false, true)] + [TestMethod] + [DataRow(true, false)] + [DataRow(false, true)] public async Task IsInvalid_If_Any_TrxOptions_Is_Missing(bool isBaseLineSet, bool isToCompareSet) { var provider = new TrxCompareToolCommandLine(new TestExtension()); diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxReportGeneratorCommandLineTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxReportGeneratorCommandLineTests.cs index 22d7e747f8..11f6621ed1 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxReportGeneratorCommandLineTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxReportGeneratorCommandLineTests.cs @@ -7,9 +7,10 @@ namespace Microsoft.Testing.Extensions.UnitTests; -[TestGroup] -public class TrxReportGeneratorCommandLineTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class TrxReportGeneratorCommandLineTests { + [TestMethod] public async Task IsValid_If_TrxFile_And_Only_TargetFilename_Is_Provided() { var provider = new TrxReportGeneratorCommandLine(); @@ -21,8 +22,9 @@ public async Task IsValid_If_TrxFile_And_Only_TargetFilename_Is_Provided() Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } - [Arguments(false, false)] - [Arguments(true, true)] + [TestMethod] + [DataRow(false, false)] + [DataRow(true, true)] public async Task IsInvalid_If_TrxFile_And_Only_TargetFilename_Are_Not_Provided(bool isTrxFile, bool hasDirectory) { var provider = new TrxReportGeneratorCommandLine(); @@ -39,8 +41,9 @@ public async Task IsInvalid_If_TrxFile_And_Only_TargetFilename_Are_Not_Provided( Assert.AreEqual(isTrxFile ? TestReports.Resources.ExtensionResources.TrxReportFileNameShouldNotContainPath : TestReports.Resources.ExtensionResources.TrxReportFileNameExtensionIsNotTrx, validateOptionsResult.ErrorMessage); } - [Arguments(false, false, true)] - [Arguments(true, true, false)] + [TestMethod] + [DataRow(false, false, true)] + [DataRow(true, true, false)] public async Task IsValid_When_TrxReport_TrxReportFile_Is_Provided_And_DiscoverTests_Not_Provided(bool isFileNameSet, bool isTrxSet, bool isDiscoverTestsSet) { var provider = new TrxReportGeneratorCommandLine(); @@ -65,8 +68,9 @@ public async Task IsValid_When_TrxReport_TrxReportFile_Is_Provided_And_DiscoverT Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } - [Arguments(true, false, false)] - [Arguments(true, true, true)] + [TestMethod] + [DataRow(true, false, false)] + [DataRow(true, true, true)] public async Task IsInvalid_When_TrxReport_TrxReportFile_Is_Provided_And_DiscoverTests_Provided(bool isFileNameSet, bool isTrxSet, bool isDiscoverTestsSet) { var provider = new TrxReportGeneratorCommandLine(); diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs index e411f49abc..9ba22507da 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxTests.cs @@ -20,8 +20,8 @@ namespace Microsoft.Testing.Extensions.UnitTests; -[TestGroup] -public class TrxTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public class TrxTests { private readonly Mock _environmentMock = new(); private readonly Mock _commandLineOptionsMock = new(); @@ -33,6 +33,7 @@ public class TrxTests(ITestExecutionContext testExecutionContext) : TestBase(tes private readonly Dictionary> _artifactsByTestNode = new(); private readonly Dictionary> _artifactsByExtension = new(); + [TestMethod] public async Task TrxReportEngine_GenerateReportAsyncWithNullAdapterSupportTrxCapability_TrxDoesNotContainClassName() { // Arrange @@ -51,6 +52,7 @@ public async Task TrxReportEngine_GenerateReportAsyncWithNullAdapterSupportTrxCa Assert.IsFalse(trxContent.Contains(@"className=")); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsyncWithNotExecutedTests_TrxExecutedTestsCountHasIt() { // Arrange @@ -69,6 +71,7 @@ public async Task TrxReportEngine_GenerateReportAsyncWithNotExecutedTests_TrxExe Assert.IsTrue(trxContent.Contains(@"notExecuted=""1""")); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsyncWithTimeoutTests_TrxTimeoutTestsCountHasIt() { // Arrange @@ -87,6 +90,7 @@ public async Task TrxReportEngine_GenerateReportAsyncWithTimeoutTests_TrxTimeout Assert.IsTrue(trxContent.Contains(@"timeout=""1""")); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithArgumentTrxReportFileName_FileIsCorrectlyGenerated() { // Arrange @@ -105,6 +109,7 @@ public async Task TrxReportEngine_GenerateReportAsync_WithArgumentTrxReportFileN AssertTrxOutcome(xml, "Completed"); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithInvalidArgumentValueForTrxReportFileName_FileIsGeneratedWithNormalizedName() { // Arrange @@ -123,6 +128,7 @@ public async Task TrxReportEngine_GenerateReportAsync_WithInvalidArgumentValueFo AssertTrxOutcome(xml, "Completed"); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithTestHostCrash_ResultSummaryOutcomeIsFailed() { // Arrange @@ -139,6 +145,7 @@ public async Task TrxReportEngine_GenerateReportAsync_WithTestHostCrash_ResultSu AssertTrxOutcome(xml, "Failed"); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithTestSkipped_ResultSummaryOutcomeIsCompleted() { // Arrange @@ -155,6 +162,7 @@ public async Task TrxReportEngine_GenerateReportAsync_WithTestSkipped_ResultSumm AssertTrxOutcome(xml, "Completed"); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithTestFailed_WithStandardErrorTrxMessage_TrxContainsStdErr() { // Arrange @@ -184,9 +192,10 @@ public async Task TrxReportEngine_GenerateReportAsync_WithTestFailed_WithStandar "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithTestFailed_WithoutStandardErrorTrxMessage_TrxContainsStdOut() { // Arrange @@ -211,9 +220,10 @@ public async Task TrxReportEngine_GenerateReportAsync_WithTestFailed_WithoutStan "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithTestFailed_WithoutStandardErrorTrxMessage_TrxContainsErrorInfo() { // Arrange @@ -241,9 +251,10 @@ public async Task TrxReportEngine_GenerateReportAsync_WithTestFailed_WithoutStan "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_PassedTestWithTestCategory_TrxContainsTestCategory() { // Arrange @@ -267,9 +278,10 @@ public async Task TrxReportEngine_GenerateReportAsync_PassedTestWithTestCategory "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_FailedTestWithTestCategory_TrxContainsTestCategory() { // Arrange @@ -293,9 +305,10 @@ public async Task TrxReportEngine_GenerateReportAsync_FailedTestWithTestCategory "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithAdapterSupportTrxCapability_TrxContainsClassName() { // Arrange @@ -314,9 +327,10 @@ public async Task TrxReportEngine_GenerateReportAsync_WithAdapterSupportTrxCapab XDocument xml = GetTrxContent(memoryStream); AssertTrxOutcome(xml, "Completed"); string trxContent = xml.ToString(); - Assert.That(trxContent.Contains(@"className=""TrxFullyQualifiedTypeName"), trxContent); + Assert.IsTrue(trxContent.Contains(@"className=""TrxFullyQualifiedTypeName"), trxContent); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNode_TrxContainsResultFile() { // Arrange @@ -340,9 +354,10 @@ public async Task TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNode_Tr "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_WithArtifactsByExtension_TrxContainsCollectorDataEntries() { // Arrange @@ -372,9 +387,10 @@ public async Task TrxReportEngine_GenerateReportAsync_WithArtifactsByExtension_T "; - Assert.That(Regex.IsMatch(trxContent, trxContentsPattern)); + Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern)); } + [TestMethod] public async Task TrxReportEngine_GenerateReportAsync_FileAlreadyExists_WillRetry() { // Arrange @@ -422,7 +438,6 @@ private static void AssertTrxOutcome(XDocument xml, string expectedOutcome) Assert.IsNotNull(resultSummary); XAttribute? outcome = resultSummary.FirstAttribute; Assert.IsNotNull(outcome); - Assert.IsNotNull(outcome.Value); Assert.IsTrue(outcome.Value.Equals(expectedOutcome, StringComparison.Ordinal)); } diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/RunSettingsCommandLineOptionsProviderTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/RunSettingsCommandLineOptionsProviderTests.cs index 03f91ef640..b4e782d03f 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/RunSettingsCommandLineOptionsProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/RunSettingsCommandLineOptionsProviderTests.cs @@ -13,10 +13,10 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.CommandLine; -[TestGroup] -public sealed class RunSettingsCommandLineOptionsProviderTests(ITestExecutionContext testExecutionContext) - : TestBase(testExecutionContext) +[TestClass] +public sealed class RunSettingsCommandLineOptionsProviderTests { + [TestMethod] public async Task RunSettingsOption_WhenFileDoesNotExist_IsNotValid() { // Arrange @@ -35,6 +35,7 @@ public async Task RunSettingsOption_WhenFileDoesNotExist_IsNotValid() Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, ExtensionResources.RunsettingsFileDoesNotExist, filePath), result.ErrorMessage); } + [TestMethod] public async Task RunSettingsOption_WhenFileCannotBeOpen_IsNotValid() { // Arrange @@ -54,6 +55,7 @@ public async Task RunSettingsOption_WhenFileCannotBeOpen_IsNotValid() Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, ExtensionResources.RunsettingsFileCannotBeRead, filePath), result.ErrorMessage); } + [TestMethod] public async Task RunSettingsOption_WhenFileExistsAndCanBeOpen_IsValid() { // Arrange diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs index 7677aef16d..06225f002d 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs @@ -10,10 +10,10 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.CommandLine; -[TestGroup] -public sealed class TestRunParameterCommandLineOptionsProviderTests(ITestExecutionContext testExecutionContext) - : TestBase(testExecutionContext) +[TestClass] +public sealed class TestRunParameterCommandLineOptionsProviderTests { + [TestMethod] public async Task TestRunParameterOption_WhenArgumentDoesNotContainEqual_IsNotValid() { // Arrange @@ -28,6 +28,7 @@ public async Task TestRunParameterOption_WhenArgumentDoesNotContainEqual_IsNotVa Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, ExtensionResources.TestRunParameterOptionArgumentIsNotParameter, "something"), result.ErrorMessage); } + [TestMethod] public async Task TestRunParameterOption_WhenArgumentContainsEqual_IsValid() { // Arrange diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj index fa5aae3fee..b7ade1f8e0 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj @@ -3,7 +3,7 @@ $(TargetFrameworks);net462 false - true + true Exe diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs index ab1f69cd40..c546179a91 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/ObjectModelConvertersTests.cs @@ -10,19 +10,17 @@ using Microsoft.Testing.Platform.TestHost; using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using TestResult = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult; + namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.ObjectModel; -[TestGroup] -public sealed class ObjectModelConvertersTests : TestBase +[TestClass] +public sealed class ObjectModelConvertersTests { private static readonly IClientInfo TestClient = new ClientInfoService("UnitTest", string.Empty); private static readonly IClientInfo VSTestClient = new ClientInfoService(WellKnownClients.VisualStudio, string.Empty); - public ObjectModelConvertersTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void ToTestNode_WhenTestCaseHasDisplayName_TestNodeDisplayNameUsesIt() { TestCase testCase = new("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs") @@ -34,6 +32,7 @@ public void ToTestNode_WhenTestCaseHasDisplayName_TestNodeDisplayNameUsesIt() Assert.AreEqual("MyDisplayName", testNode.DisplayName); } + [TestMethod] public void ToTestNode_WhenTestCaseHasNoDisplayName_TestNodeDisplayNameUsesIt() { TestCase testCase = new("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs"); @@ -42,6 +41,7 @@ public void ToTestNode_WhenTestCaseHasNoDisplayName_TestNodeDisplayNameUsesIt() Assert.AreEqual("SomeFqn", testNode.DisplayName); } + [TestMethod] public void ToTestNode_WhenTestResultHasCodeFilePath_SetsTestFileLocationProperty() { TestResult testResult = new(new("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs") @@ -52,6 +52,7 @@ public void ToTestNode_WhenTestResultHasCodeFilePath_SetsTestFileLocationPropert Assert.AreEqual("FilePath", testNode.Properties.Single().FilePath); } + [TestMethod] public void ToTestNode_WhenTestResultOutcomeIsFailed_TestNodePropertiesContainFailedTestNodeStateProperty() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -63,12 +64,13 @@ public void ToTestNode_WhenTestResultOutcomeIsFailed_TestNodePropertiesContainFa var testNode = testResult.ToTestNode(false, TestClient); FailedTestNodeStateProperty[] failedTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(failedTestNodeStateProperties.Length == 1); + Assert.AreEqual(1, failedTestNodeStateProperties.Length); Assert.IsTrue(failedTestNodeStateProperties[0].Exception is VSTestException); Assert.AreEqual(testResult.ErrorStackTrace, failedTestNodeStateProperties[0].Exception!.StackTrace); Assert.AreEqual(testResult.ErrorMessage, failedTestNodeStateProperties[0].Exception!.Message); } + [TestMethod] public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestProperty_TestNodePropertiesContainTheCategoryInTraits() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")); @@ -78,12 +80,13 @@ public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestProperty var testNode = testResult.ToTestNode(false, VSTestClient); SerializableNamedKeyValuePairsStringProperty[] errorTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(errorTestNodeStateProperties.Length == 1); - Assert.IsTrue(errorTestNodeStateProperties[0].Name == "traits"); - Assert.IsTrue(errorTestNodeStateProperties[0].Pairs.Length == 1); - Assert.IsTrue(errorTestNodeStateProperties[0].Pairs[0].Key == "category1"); + Assert.AreEqual(1, errorTestNodeStateProperties.Length); + Assert.AreEqual("traits", errorTestNodeStateProperties[0].Name); + Assert.AreEqual(1, errorTestNodeStateProperties[0].Pairs.Length); + Assert.AreEqual("category1", errorTestNodeStateProperties[0].Pairs[0].Key); } + [TestMethod] public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestPropertyWithTrxEnabled_TestNodePropertiesContainTrxCategoriesProperty() { TestResult testResult = new(new TestCase("assembly.class.SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")); @@ -93,11 +96,12 @@ public void ToTestNode_WhenTestResultHasMSTestDiscovererTestCategoryTestProperty var testNode = testResult.ToTestNode(true, VSTestClient); TrxCategoriesProperty[] trxCategoriesProperty = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(trxCategoriesProperty.Length == 1); - Assert.IsTrue(trxCategoriesProperty[0].Categories.Length == 1); - Assert.AreEqual(trxCategoriesProperty[0].Categories[0], "category1"); + Assert.AreEqual(1, trxCategoriesProperty.Length); + Assert.AreEqual(1, trxCategoriesProperty[0].Categories.Length); + Assert.AreEqual("category1", trxCategoriesProperty[0].Categories[0]); } + [TestMethod] public void ToTestNode_WhenTestResultHasTestCaseHierarchyTestProperty_TestNodePropertiesContainItInSerializableNamedArrayStringProperty() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")); @@ -107,13 +111,14 @@ public void ToTestNode_WhenTestResultHasTestCaseHierarchyTestProperty_TestNodePr var testNode = testResult.ToTestNode(false, VSTestClient); SerializableNamedArrayStringProperty[] trxCategoriesProperty = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(trxCategoriesProperty.Length == 1); - Assert.AreEqual(trxCategoriesProperty[0].Values[0], "assembly"); - Assert.AreEqual(trxCategoriesProperty[0].Values[1], "class"); - Assert.AreEqual(trxCategoriesProperty[0].Values[2], "category"); - Assert.AreEqual(trxCategoriesProperty[0].Values[3], "test"); + Assert.AreEqual(1, trxCategoriesProperty.Length); + Assert.AreEqual("assembly", trxCategoriesProperty[0].Values[0]); + Assert.AreEqual("class", trxCategoriesProperty[0].Values[1]); + Assert.AreEqual("category", trxCategoriesProperty[0].Values[2]); + Assert.AreEqual("test", trxCategoriesProperty[0].Values[3]); } + [TestMethod] public void ToTestNode_WhenTestResultHasOriginalExecutorUriProperty_TestNodePropertiesContainItInSerializableKeyValuePairStringProperty() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")); @@ -125,11 +130,12 @@ public void ToTestNode_WhenTestResultHasOriginalExecutorUriProperty_TestNodeProp var testNode = testResult.ToTestNode(false, VSTestClient); SerializableKeyValuePairStringProperty[] serializableKeyValuePairStringProperty = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(serializableKeyValuePairStringProperty.Length == 3); - Assert.AreEqual(serializableKeyValuePairStringProperty[0].Key, VSTestTestNodeProperties.OriginalExecutorUriPropertyName); - Assert.AreEqual(serializableKeyValuePairStringProperty[0].Value, "https://vs.com/"); + Assert.AreEqual(3, serializableKeyValuePairStringProperty.Length); + Assert.AreEqual(VSTestTestNodeProperties.OriginalExecutorUriPropertyName, serializableKeyValuePairStringProperty[0].Key); + Assert.AreEqual("https://vs.com/", serializableKeyValuePairStringProperty[0].Value); } + [TestMethod] public void ToTestNode_WhenTestResultHasFullyQualifiedTypeAndTrxEnabled_TestNodeHasFullyQualifiedTypeName() { TestResult testResult = new(new TestCase("assembly.class.test", new("executor://uri", UriKind.Absolute), "source.cs")); @@ -140,15 +146,17 @@ public void ToTestNode_WhenTestResultHasFullyQualifiedTypeAndTrxEnabled_TestNode Assert.AreEqual("assembly.class", testNode.Properties.Single().FullyQualifiedTypeName); } + [TestMethod] public void ToTestNode_WhenTestResultHasNoFullyQualifiedTypeAndTrxEnabled_Throws() { TestResult testResult = new(new TestCase("test", new("executor://uri", UriKind.Absolute), "source.cs")); - string errorMessage = Assert.Throws(() => testResult.ToTestNode(true, TestClient)).Message; + string errorMessage = Assert.ThrowsException(() => testResult.ToTestNode(true, TestClient)).Message; Assert.IsTrue(errorMessage.Contains("Unable to parse fully qualified type name from test case: ")); } + [TestMethod] public void ToTestNode_FromTestResult_TestNodePropertiesContainCorrectTimingProperty() { var startTime = new DateTime(1996, 8, 22, 20, 30, 5); @@ -167,6 +175,7 @@ public void ToTestNode_FromTestResult_TestNodePropertiesContainCorrectTimingProp Assert.AreEqual(testNode.Properties.OfType()[0], testResultTimingProperty); } + [TestMethod] public void ToTestNode_WhenTestResultOutcomeIsNotFoundWithoutSetErrorMessage_TestNodePropertiesContainErrorTestNodeStatePropertyWithDefaultErrorMessage() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -177,12 +186,13 @@ public void ToTestNode_WhenTestResultOutcomeIsNotFoundWithoutSetErrorMessage_Tes var testNode = testResult.ToTestNode(false, TestClient); ErrorTestNodeStateProperty[] errorTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(errorTestNodeStateProperties.Length == 1); + Assert.AreEqual(1, errorTestNodeStateProperties.Length); Assert.IsTrue(errorTestNodeStateProperties[0].Exception is VSTestException); Assert.AreEqual(testResult.ErrorStackTrace, errorTestNodeStateProperties[0].Exception!.StackTrace); Assert.IsTrue(errorTestNodeStateProperties[0].Exception!.Message.Contains("Not found")); } + [TestMethod] public void ToTestNode_WhenTestResultOutcomeIsSkipped_TestNodePropertiesContainSkippedTestNodeStateProperty() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -192,9 +202,10 @@ public void ToTestNode_WhenTestResultOutcomeIsSkipped_TestNodePropertiesContainS var testNode = testResult.ToTestNode(false, TestClient); SkippedTestNodeStateProperty[] skipTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(skipTestNodeStateProperties.Length == 1); + Assert.AreEqual(1, skipTestNodeStateProperties.Length); } + [TestMethod] public void ToTestNode_WhenTestResultOutcomeIsNone_TestNodePropertiesContainSkippedTestNodeStateProperty() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -204,9 +215,10 @@ public void ToTestNode_WhenTestResultOutcomeIsNone_TestNodePropertiesContainSkip var testNode = testResult.ToTestNode(false, TestClient); SkippedTestNodeStateProperty[] skipTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(skipTestNodeStateProperties.Length == 1); + Assert.AreEqual(1, skipTestNodeStateProperties.Length); } + [TestMethod] public void ToTestNode_WhenTestResultOutcomeIsPassed_TestNodePropertiesContainPassedTestNodeStateProperty() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -216,9 +228,10 @@ public void ToTestNode_WhenTestResultOutcomeIsPassed_TestNodePropertiesContainPa var testNode = testResult.ToTestNode(false, TestClient); PassedTestNodeStateProperty[] passedTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(passedTestNodeStateProperties.Length == 1); + Assert.AreEqual(1, passedTestNodeStateProperties.Length); } + [TestMethod] public void ToTestNode_WhenTestResultHasUidAndDisplayNameWithWellKnownClient_TestNodePropertiesContainSerializableKeyValuePairStringPropertyTwice() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -229,12 +242,13 @@ public void ToTestNode_WhenTestResultHasUidAndDisplayNameWithWellKnownClient_Tes var testNode = testResult.ToTestNode(false, VSTestClient); SerializableKeyValuePairStringProperty[] errorTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(errorTestNodeStateProperties.Length == 2, "Expected 2 SerializableKeyValuePairStringProperty"); - Assert.IsTrue(errorTestNodeStateProperties[0].Key == "vstest.TestCase.Id"); - Assert.IsTrue(errorTestNodeStateProperties[1].Key == "vstest.TestCase.FullyQualifiedName"); - Assert.IsTrue(errorTestNodeStateProperties[1].Value == "SomeFqn"); + Assert.AreEqual(2, errorTestNodeStateProperties.Length, "Expected 2 SerializableKeyValuePairStringProperty"); + Assert.AreEqual("vstest.TestCase.Id", errorTestNodeStateProperties[0].Key); + Assert.AreEqual("vstest.TestCase.FullyQualifiedName", errorTestNodeStateProperties[1].Key); + Assert.AreEqual("SomeFqn", errorTestNodeStateProperties[1].Value); } + [TestMethod] public void ToTestNode_WhenTestResultHasTraits_TestNodePropertiesContainIt() { TestResult testResult = new(new TestCase("SomeFqn", new("executor://uri", UriKind.Absolute), "source.cs")) @@ -246,10 +260,10 @@ public void ToTestNode_WhenTestResultHasTraits_TestNodePropertiesContainIt() var testNode = testResult.ToTestNode(false, VSTestClient); SerializableNamedKeyValuePairsStringProperty[] errorTestNodeStateProperties = testNode.Properties.OfType().ToArray(); - Assert.IsTrue(errorTestNodeStateProperties.Length == 1); - Assert.IsTrue(errorTestNodeStateProperties[0].Name == "traits"); - Assert.IsTrue(errorTestNodeStateProperties[0].Pairs.Length == 1); - Assert.IsTrue(errorTestNodeStateProperties[0].Pairs[0].Key == "key"); - Assert.IsTrue(errorTestNodeStateProperties[0].Pairs[0].Value == "value"); + Assert.AreEqual(1, errorTestNodeStateProperties.Length); + Assert.AreEqual("traits", errorTestNodeStateProperties[0].Name); + Assert.AreEqual(1, errorTestNodeStateProperties[0].Pairs.Length); + Assert.AreEqual("key", errorTestNodeStateProperties[0].Pairs[0].Key); + Assert.AreEqual("value", errorTestNodeStateProperties[0].Pairs[0].Value); } } diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunContextAdapterTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunContextAdapterTests.cs index 543e1012bb..20be61bec0 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunContextAdapterTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunContextAdapterTests.cs @@ -9,17 +9,13 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.ObjectModel; -[TestGroup] -public class RunContextAdapterTests : TestBase +[TestClass] +public class RunContextAdapterTests { private readonly Mock _commandLineOptions = new(); private readonly Mock _runSettings = new(); - public RunContextAdapterTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void TestRunDirectory_IsNotNull_If_ResultsDirectory_Is_Provided() { string runSettings = @@ -38,6 +34,7 @@ public void TestRunDirectory_IsNotNull_If_ResultsDirectory_Is_Provided() Assert.IsNotNull(runContextAdapter.RunSettings); } + [TestMethod] public void TestRunDirectory_IsNull_If_ResultsDirectory_IsNot_Provided() { string runSettings = diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunSettingsPatcherTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunSettingsPatcherTests.cs index 224ed9acf9..409834e19e 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunSettingsPatcherTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/ObjectModel/RunSettingsPatcherTests.cs @@ -14,12 +14,13 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.ObjectModel; -[TestGroup] -public class RunSettingsPatcherTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public class RunSettingsPatcherTests { private readonly Mock _configuration = new(); private readonly Mock _commandLineOptions = new(); + [TestMethod] public void Patch_WhenNoRunSettingsProvided_CreateRunSettingsWithResultsDirectoryElement() { _configuration.Setup(x => x[PlatformConfigurationConstants.PlatformResultDirectory]).Returns("/PlatformResultDirectory"); @@ -30,6 +31,7 @@ public void Patch_WhenNoRunSettingsProvided_CreateRunSettingsWithResultsDirector runSettingsDocument.XPathSelectElement("RunSettings/RunConfiguration/ResultsDirectory")!.Value); } + [TestMethod] public void Patch_WithRunSettingsProvidedButMissingResultsDirectory_AddsElement() { string runSettings = """ @@ -49,6 +51,7 @@ public void Patch_WithRunSettingsProvidedButMissingResultsDirectory_AddsElement( Assert.IsTrue(bool.Parse(runSettingsDocument.XPathSelectElement("RunSettings/RunConfiguration/Canary")!.Value)); } + [TestMethod] public void Patch_WithRunSettingsContainingResultsDirectory_EntryIsNotOverridden() { string runSettings = @@ -69,6 +72,7 @@ public void Patch_WithRunSettingsContainingResultsDirectory_EntryIsNotOverridden Assert.IsTrue(bool.Parse(runSettingsDocument.XPathSelectElement("RunSettings/RunConfiguration/Canary")!.Value)); } + [TestMethod] public void Patch_WhenRunSettingsExists_MergesParameters() { string runSettings = """ @@ -94,14 +98,15 @@ public void Patch_WhenRunSettingsExists_MergesParameters() _commandLineOptions.Object); XElement[] testRunParameters = runSettingsDocument.XPathSelectElements("RunSettings/TestRunParameters/Parameter").ToArray(); - Assert.AreEqual(testRunParameters[0].Attribute("name")!.Value, "key1"); - Assert.AreEqual(testRunParameters[0].Attribute("value")!.Value, "value1"); - Assert.AreEqual(testRunParameters[1].Attribute("name")!.Value, "key2"); - Assert.AreEqual(testRunParameters[1].Attribute("value")!.Value, "updated-value"); - Assert.AreEqual(testRunParameters[2].Attribute("name")!.Value, "key3"); - Assert.AreEqual(testRunParameters[2].Attribute("value")!.Value, "value3"); + Assert.AreEqual("key1", testRunParameters[0].Attribute("name")!.Value); + Assert.AreEqual("value1", testRunParameters[0].Attribute("value")!.Value); + Assert.AreEqual("key2", testRunParameters[1].Attribute("name")!.Value); + Assert.AreEqual("updated-value", testRunParameters[1].Attribute("value")!.Value); + Assert.AreEqual("key3", testRunParameters[2].Attribute("name")!.Value); + Assert.AreEqual("value3", testRunParameters[2].Attribute("value")!.Value); } + [TestMethod] public void Patch_WhenRunSettingsDoesNotExist_AddParameters() { string[]? arguments; @@ -117,9 +122,9 @@ public void Patch_WhenRunSettingsDoesNotExist_AddParameters() _commandLineOptions.Object); XElement[] testRunParameters = runSettingsDocument.XPathSelectElements("RunSettings/TestRunParameters/Parameter").ToArray(); - Assert.AreEqual(testRunParameters[0].Attribute("name")!.Value, "key1"); - Assert.AreEqual(testRunParameters[0].Attribute("value")!.Value, "value1"); - Assert.AreEqual(testRunParameters[1].Attribute("name")!.Value, "key2"); - Assert.AreEqual(testRunParameters[1].Attribute("value")!.Value, "value2"); + Assert.AreEqual("key1", testRunParameters[0].Attribute("name")!.Value); + Assert.AreEqual("value1", testRunParameters[0].Attribute("value")!.Value); + Assert.AreEqual("key2", testRunParameters[1].Attribute("name")!.Value); + Assert.AreEqual("value2", testRunParameters[1].Attribute("value")!.Value); } } diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Program.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Program.cs index 0b997618f7..8c64d561f7 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Program.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Program.cs @@ -1,16 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Reflection; + using Microsoft.Testing.Extensions; -using Microsoft.Testing.Extensions.VSTestBridge.UnitTests; -ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new SourceGeneratedTestNodesBuilder()); +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] #if NETCOREAPP Console.WriteLine("Dynamic code supported: " + System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported); #endif +ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); + +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); + #if !NATIVE_AOT #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Properties/launchSettings.json b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Properties/launchSettings.json index ea079cb247..23c4781b41 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Properties/launchSettings.json +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Microsoft.Testing.Extensions.VSTestBridge.UnitTests": { "commandName": "Project", - "commandLineArgs": "--treenode-filter /*/*/*/**", + "commandLineArgs": "", "environmentVariables": { } } diff --git a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/MSBuildTests.cs b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/MSBuildTests.cs index 503931e844..79a669510d 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/MSBuildTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/MSBuildTests.cs @@ -4,38 +4,27 @@ using System.Collections; using Microsoft.Build.Framework; -#if NET8_0_OR_GREATER + using Moq; -#endif namespace Microsoft.Testing.Platform.MSBuild.UnitTests; -[TestGroup] -public class MSBuildTests : TestBase +[TestClass] +public sealed class MSBuildTests { -#if NET8_0_OR_GREATER private readonly Mock _buildEngine; private readonly List _errors; -#endif - public MSBuildTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public MSBuildTests() { -#if NET8_0_OR_GREATER _buildEngine = new Mock(); _errors = new List(); _buildEngine.Setup(x => x.LogErrorEvent(It.IsAny())).Callback(e => _errors.Add(e)); -#endif } + [TestMethod] public void Verify_Correct_Registration_Order_For_WellKnown_Extensions() { -#if !NET8_0_OR_GREATER - // On netfx, net6.0, and net7.0 this is failing with: - // Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. - // This is because the NuGet Package is "compatible" with netstandard2.0, so it can be installed everywhere, but it restores dlls only into specific (new) versions of .NET Framework and .NET. - return; -#else InMemoryFileSystem inMemoryFileSystem = new(); TestingPlatformEntryPointTask testingPlatformEntryPoint = new(inMemoryFileSystem) { @@ -69,7 +58,6 @@ internal sealed class TestingPlatformEntryPoint """; Assert.AreEqual(expectedSourceOrder, inMemoryFileSystem.Files["obj/entryPointFile"]); -#endif } private sealed class InMemoryFileSystem : IFileSystem diff --git a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests.csproj b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests.csproj index 87bee4bfd3..d5a6455762 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests.csproj +++ b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests.csproj @@ -1,9 +1,9 @@ - $(MicrosoftTestingTargetFrameworks);net462 + net8.0;net9.0 false - true + true Exe diff --git a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Program.cs b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Program.cs index 45d399bd11..2057080ba4 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Program.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Program.cs @@ -1,11 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Reflection; + using Microsoft.Testing.Extensions; +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] + // DebuggerUtility.AttachVSToCurrentProcess(); ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new Microsoft.Testing.Platform.MSBuild.UnitTests.SourceGeneratedTestNodesBuilder()); +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); #endif diff --git a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Usings.cs b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Usings.cs index a91def1ab6..10fe4382b8 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Usings.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Usings.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -global using Microsoft.Testing.Internal.Framework; global using Microsoft.Testing.Platform.Builder; global using Microsoft.Testing.Platform.Extensions; global using Microsoft.Testing.TestInfrastructure; diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ArgumentArityTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ArgumentArityTests.cs index 33921a8451..5cada34ede 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ArgumentArityTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/ArgumentArityTests.cs @@ -10,8 +10,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class ArgumentArityTests : TestBase +[TestClass] +public sealed class ArgumentArityTests { private readonly ICommandLineOptionsProvider[] _systemCommandLineOptionsProviders = [ @@ -23,11 +23,7 @@ public class ArgumentArityTests : TestBase new ExtensionCommandLineProviderMockOptionsWithDifferentArity() ]; - public ArgumentArityTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task ParseAndValidate_WhenOptionWithArityZeroIsCalledWithOneArgument_ReturnsFalse() { // Arrange @@ -43,6 +39,7 @@ public async Task ParseAndValidate_WhenOptionWithArityZeroIsCalledWithOneArgumen Assert.AreEqual("Option '--zeroArgumentsOption' from provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider) expects no arguments", result.ErrorMessage, StringComparer.Ordinal); } + [TestMethod] public async Task ParseAndValidate_WhenOptionWithArityExactlyOneIsCalledWithTwoArguments_ReturnsFalse() { // Arrange @@ -58,6 +55,7 @@ public async Task ParseAndValidate_WhenOptionWithArityExactlyOneIsCalledWithTwoA Assert.AreEqual("Option '--exactlyOneArgumentsOption' from provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider) expects at most 1 arguments", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidate_WhenOptionWithArityExactlyOneIsCalledWithoutArguments_ReturnsFalse() { // Arrange @@ -73,6 +71,7 @@ public async Task ParseAndValidate_WhenOptionWithArityExactlyOneIsCalledWithoutA Assert.AreEqual("Option '--exactlyOneArgumentsOption' from provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider) expects at least 1 arguments", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidate_WhenOptionWithArityZeroOrOneIsCalledWithTwoArguments_ReturnsFalse() { // Arrange @@ -88,6 +87,7 @@ public async Task ParseAndValidate_WhenOptionWithArityZeroOrOneIsCalledWithTwoAr Assert.AreEqual("Option '--zeroOrOneArgumentsOption' from provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider) expects at most 1 arguments", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidate_WhenOptionWithArityOneOrMoreIsCalledWithoutArguments_ReturnsFalse() { // Arrange @@ -103,6 +103,7 @@ public async Task ParseAndValidate_WhenOptionWithArityOneOrMoreIsCalledWithoutAr Assert.AreEqual("Option '--oneOrMoreArgumentsOption' from provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider) expects at least 1 arguments", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidate_WhenOptionsGetsTheExpectedNumberOfArguments_ReturnsTrue() { // Arrange diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index b7544c39ee..c192ec482f 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -12,8 +12,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class CommandLineHandlerTests : TestBase +[TestClass] +public sealed class CommandLineHandlerTests { private readonly Mock _outputDisplayMock = new(); private readonly Mock _testApplicationModuleInfoMock = new(); @@ -25,11 +25,7 @@ public class CommandLineHandlerTests : TestBase private readonly ICommandLineOptionsProvider[] _extensionCommandLineOptionsProviders = []; - public CommandLineHandlerTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task ParseAndValidateAsync_InvalidCommandLineArguments_ReturnsFalse() { // Arrange @@ -42,10 +38,11 @@ public async Task ParseAndValidateAsync_InvalidCommandLineArguments_ReturnsFalse // Assert Assert.IsFalse(result.IsValid); - Assert.Contains("Invalid command line arguments:", result.ErrorMessage); - Assert.Contains("Unexpected argument 'a'", result.ErrorMessage); + StringAssert.Contains(result.ErrorMessage, "Invalid command line arguments:"); + StringAssert.Contains(result.ErrorMessage, "Unexpected argument 'a'"); } + [TestMethod] public async Task ParseAndValidateAsync_EmptyCommandLineArguments_ReturnsTrue() { // Arrange @@ -60,6 +57,7 @@ public async Task ParseAndValidateAsync_EmptyCommandLineArguments_ReturnsTrue() Assert.IsTrue(result.IsValid); } + [TestMethod] public async Task ParseAndValidateAsync_DuplicateOption_ReturnsFalse() { // Arrange @@ -77,9 +75,10 @@ public async Task ParseAndValidateAsync_DuplicateOption_ReturnsFalse() // Assert Assert.IsFalse(result.IsValid); - Assert.Contains("Option '--userOption' is declared by multiple extensions: 'Microsoft Testing Platform command line provider', 'Microsoft Testing Platform command line provider'", result.ErrorMessage); + StringAssert.Contains(result.ErrorMessage, "Option '--userOption' is declared by multiple extensions: 'Microsoft Testing Platform command line provider', 'Microsoft Testing Platform command line provider'"); } + [TestMethod] public async Task ParseAndValidateAsync_InvalidOption_ReturnsFalse() { // Arrange @@ -95,6 +94,7 @@ public async Task ParseAndValidateAsync_InvalidOption_ReturnsFalse() Assert.AreEqual("Option '--diagnostic-verbosity' has invalid arguments: '--diagnostic-verbosity' expects a single level argument ('Trace', 'Debug', 'Information', 'Warning', 'Error', or 'Critical')", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidateAsync_InvalidArgumentArity_ReturnsFalse() { // Arrange @@ -110,6 +110,7 @@ public async Task ParseAndValidateAsync_InvalidArgumentArity_ReturnsFalse() Assert.AreEqual("Option '--help' from provider 'Platform command line provider' (UID: PlatformCommandLineProvider) expects no arguments", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidateAsync_ReservedOptions_ReturnsFalse() { // Arrange @@ -129,6 +130,7 @@ public async Task ParseAndValidateAsync_ReservedOptions_ReturnsFalse() Assert.AreEqual("Option '--help' is reserved and cannot be used by providers: 'help'", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidateAsync_ReservedOptionsPrefix_ReturnsFalse() { // Arrange @@ -148,6 +150,7 @@ public async Task ParseAndValidateAsync_ReservedOptionsPrefix_ReturnsFalse() Assert.AreEqual("Option `--internal-customextension` from provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider) is using the reserved prefix '--internal'", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidateAsync_UnknownOption_ReturnsFalse() { // Arrange @@ -168,6 +171,7 @@ public async Task ParseAndValidateAsync_UnknownOption_ReturnsFalse() Assert.AreEqual("Unknown option '--x'", result.ErrorMessage); } + [TestMethod] public async Task ParseAndValidateAsync_InvalidValidConfiguration_ReturnsFalse() { // Arrange @@ -187,6 +191,7 @@ public async Task ParseAndValidateAsync_InvalidValidConfiguration_ReturnsFalse() Assert.AreEqual("Invalid configuration for provider 'Microsoft Testing Platform command line provider' (UID: PlatformCommandLineProvider). Error: Invalid configuration errorMessage", result.ErrorMessage); } + [TestMethod] public void IsHelpInvoked_HelpOptionSet_ReturnsTrue() { // Arrange @@ -204,6 +209,7 @@ public void IsHelpInvoked_HelpOptionSet_ReturnsTrue() _outputDisplayMock.Verify(o => o.DisplayBannerAsync(It.IsAny()), Times.Never); } + [TestMethod] public void IsInfoInvoked_InfoOptionSet_ReturnsTrue() { // Arrange @@ -221,6 +227,7 @@ public void IsInfoInvoked_InfoOptionSet_ReturnsTrue() _outputDisplayMock.Verify(o => o.DisplayBannerAsync(It.IsAny()), Times.Never); } + [TestMethod] public void IsVersionInvoked_VersionOptionSet_ReturnsTrue() { // Arrange @@ -238,6 +245,7 @@ public void IsVersionInvoked_VersionOptionSet_ReturnsTrue() _outputDisplayMock.Verify(o => o.DisplayBannerAsync(It.IsAny()), Times.Never); } + [TestMethod] public void GetOptionValue_OptionExists_ReturnsOptionValue() { // Arrange @@ -251,12 +259,13 @@ public void GetOptionValue_OptionExists_ReturnsOptionValue() // Assert Assert.IsTrue(result); - Assert.IsFalse(optionValue is null); + Assert.IsNotNull(optionValue); Assert.AreEqual(optionValue?.Length, 2); Assert.AreEqual("value1", optionValue?[0]); Assert.AreEqual("value2", optionValue?[1]); } + [TestMethod] public void GetOptionValue_OptionDoesNotExist_ReturnsNull() { // Arrange @@ -278,7 +287,7 @@ public void GetOptionValue_OptionDoesNotExist_ReturnsNull() // Assert Assert.IsFalse(result); - Assert.IsTrue(optionValue is null); + Assert.IsNull(optionValue); } private sealed class ExtensionCommandLineProviderMockReservedOptions : ICommandLineOptionsProvider diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs index bd1f756bb7..7f426c4ef5 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs @@ -1,19 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Reflection; + using Microsoft.Testing.Platform.CommandLine; using Microsoft.Testing.Platform.Extensions.CommandLine; using Microsoft.Testing.Platform.Helpers; namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class CommandLineTests : TestBase +[TestClass] +public sealed class CommandLineTests { // The test method ParserTests is parameterized and one of the parameter needs to be CommandLineParseResult. // The test method has to be public to be run, but CommandLineParseResult is internal. // So, we introduce this wrapper to be used instead so that the test method can be made public. - public class CommandLineParseResultWrapper + public sealed class CommandLineParseResultWrapper { internal CommandLineParseResultWrapper(string? toolName, IReadOnlyList options, IReadOnlyList errors) => Result = new CommandLineParseResult(toolName, options, errors); @@ -21,12 +23,8 @@ internal CommandLineParseResultWrapper(string? toolName, IReadOnlyList ParserTestDataFormat(TestArgumentsContext ctx) + public static string ParserTestDataFormat(MethodInfo methodInfo, object?[]? data) { - (int TestNum, string[] Args, (string RspFileName, string RspFileContent)[]? RspFiles, CommandLineParseResultWrapper ParseResult) item = ((int, string[], (string, string)[], CommandLineParseResultWrapper))ctx.Arguments; + (int testNum, string[] args, (string RspFileName, string RspFileContent)[]? rspFiles, CommandLineParseResultWrapper parseResult) = ((int)data![0]!, (string[])data[1]!, ((string, string)[])data[2]!, (CommandLineParseResultWrapper)data[3]!); - return item.TestNum == 13 - ? new(item, $"\"--option1\", $@\" \"\" \\{{Environment.NewLine}} \"\" \" {item.TestNum}") - : new(item, $"{item.Args.Aggregate((a, b) => $"{a} {b}")} {item.TestNum}"); + return testNum == 13 + ? $"\"--option1\", $@\" \"\" \\{{Environment.NewLine}} \"\" \" {testNum}" + : $"{args.Aggregate((a, b) => $"{a} {b}")} {testNum}"; } internal static IEnumerable<(int TestNum, string[] Args, (string RspFileName, string RspFileContent)[]? RspFiles, CommandLineParseResultWrapper ParseResult)> ParserTestsData() @@ -204,6 +202,7 @@ public void ParserTests(int testNum, string[] args, (string RspFileName, string }.ToArray(), [])); } + [TestMethod] public void CommandLineOptionWithNumber_IsSupported() { _ = new CommandLineOption("123", "sample", ArgumentArity.ZeroOrOne, false); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs index b108c5ed59..bc1fb5ee9b 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/PlatformCommandLineProviderTests.cs @@ -10,20 +10,16 @@ namespace Microsoft.Testing.Platform.UnitTests.CommandLine; -[TestGroup] -public class PlatformCommandLineProviderTests : TestBase +[TestClass] +public sealed class PlatformCommandLineProviderTests { - public PlatformCommandLineProviderTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - - [Arguments("Trace")] - [Arguments("Debug")] - [Arguments("Information")] - [Arguments("Warning")] - [Arguments("Error")] - [Arguments("Critical")] + [TestMethod] + [DataRow("Trace")] + [DataRow("Debug")] + [DataRow("Information")] + [DataRow("Warning")] + [DataRow("Error")] + [DataRow("Critical")] public async Task IsValid_If_Verbosity_Has_CorrectValue(string dumpType) { var provider = new PlatformCommandLineProvider(); @@ -34,6 +30,7 @@ public async Task IsValid_If_Verbosity_Has_CorrectValue(string dumpType) Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } + [TestMethod] public async Task IsInvalid_If_Verbosity_Has_IncorrectValue() { var provider = new PlatformCommandLineProvider(); @@ -44,6 +41,7 @@ public async Task IsInvalid_If_Verbosity_Has_IncorrectValue() Assert.AreEqual(PlatformResources.PlatformCommandLineDiagnosticOptionExpectsSingleArgumentErrorMessage, validateOptionsResult.ErrorMessage); } + [TestMethod] public async Task IsValid_If_ClientPort_Is_Integer() { var provider = new PlatformCommandLineProvider(); @@ -54,8 +52,9 @@ public async Task IsValid_If_ClientPort_Is_Integer() Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } - [Arguments("32.32")] - [Arguments("invalid")] + [TestMethod] + [DataRow("32.32")] + [DataRow("invalid")] public async Task IsInvalid_If_ClientPort_Is_Not_Integer(string clientPort) { var provider = new PlatformCommandLineProvider(); @@ -66,6 +65,7 @@ public async Task IsInvalid_If_ClientPort_Is_Not_Integer(string clientPort) Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, PlatformResources.PlatformCommandLinePortOptionSingleArgument, PlatformCommandLineProvider.ClientPortOptionKey), validateOptionsResult.ErrorMessage); } + [TestMethod] public async Task IsValid_If_ExitOnProcessExit_Is_Integer() { var provider = new PlatformCommandLineProvider(); @@ -76,8 +76,9 @@ public async Task IsValid_If_ExitOnProcessExit_Is_Integer() Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } - [Arguments("32.32")] - [Arguments("invalid")] + [TestMethod] + [DataRow("32.32")] + [DataRow("invalid")] public async Task IsInvalid_If_ExitOnProcessExit_Is_Not_Integer(string pid) { var provider = new PlatformCommandLineProvider(); @@ -88,6 +89,7 @@ public async Task IsInvalid_If_ExitOnProcessExit_Is_Not_Integer(string pid) Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, PlatformResources.PlatformCommandLineExitOnProcessExitSingleArgument, PlatformCommandLineProvider.ExitOnProcessExitOptionKey), validateOptionsResult.ErrorMessage); } + [TestMethod] public async Task IsValid_If_Diagnostics_Provided_With_Other_Diagnostics_Provided() { var provider = new PlatformCommandLineProvider(); @@ -103,6 +105,7 @@ public async Task IsValid_If_Diagnostics_Provided_With_Other_Diagnostics_Provide Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } + [TestMethod] public async Task IsValid_When_NoOptionSpecified() { var provider = new PlatformCommandLineProvider(); @@ -112,9 +115,10 @@ public async Task IsValid_When_NoOptionSpecified() Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } - [Arguments(PlatformCommandLineProvider.DiagnosticOutputDirectoryOptionKey)] - [Arguments(PlatformCommandLineProvider.DiagnosticOutputFilePrefixOptionKey)] + [DataRow(PlatformCommandLineProvider.DiagnosticOutputDirectoryOptionKey)] + [DataRow(PlatformCommandLineProvider.DiagnosticOutputFilePrefixOptionKey)] + [TestMethod] public async Task IsNotValid_If_Diagnostics_Missing_When_OthersDiagnostics_Provided(string optionName) { var provider = new PlatformCommandLineProvider(); @@ -128,9 +132,10 @@ public async Task IsNotValid_If_Diagnostics_Missing_When_OthersDiagnostics_Provi Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, PlatformResources.PlatformCommandLineDiagnosticOptionIsMissing, optionName), validateOptionsResult.ErrorMessage); } - [Arguments(true, false)] - [Arguments(false, true)] - [Arguments(false, false)] + [TestMethod] + [DataRow(true, false)] + [DataRow(false, true)] + [DataRow(false, false)] public async Task IsValid_When_Both_DiscoverTests_MinimumExpectedTests_NotProvided(bool discoverTestsSet, bool minimumExpectedTestsSet) { var provider = new PlatformCommandLineProvider(); @@ -150,6 +155,7 @@ public async Task IsValid_When_Both_DiscoverTests_MinimumExpectedTests_NotProvid Assert.IsTrue(string.IsNullOrEmpty(validateOptionsResult.ErrorMessage)); } + [TestMethod] public async Task IsInvalid_When_Both_DiscoverTests_MinimumExpectedTests_Provided() { var provider = new PlatformCommandLineProvider(); @@ -164,6 +170,7 @@ public async Task IsInvalid_When_Both_DiscoverTests_MinimumExpectedTests_Provide Assert.AreEqual(PlatformResources.PlatformCommandLineMinimumExpectedTestsIncompatibleDiscoverTests, validateOptionsResult.ErrorMessage); } + [TestMethod] public async Task IsNotValid_If_ExitOnProcess_Not_Running() { var provider = new PlatformCommandLineProvider(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/TreeNodeFilterCommandLineOptionsProviderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/TreeNodeFilterCommandLineOptionsProviderTests.cs index 2b865e70f2..873a57df4f 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/TreeNodeFilterCommandLineOptionsProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/TreeNodeFilterCommandLineOptionsProviderTests.cs @@ -7,14 +7,10 @@ namespace Microsoft.Testing.Platform.UnitTests.CommandLine; -[TestGroup] -public class TreeNodeFilterCommandLineOptionsProviderTests : TestBase +[TestClass] +public sealed class TreeNodeFilterCommandLineOptionsProviderTests { - public TreeNodeFilterCommandLineOptionsProviderTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task TreenodeFilter_AlwaysValid() { var provider = new TreeNodeFilterCommandLineOptionsProvider(new TestExtension()); @@ -24,6 +20,7 @@ public async Task TreenodeFilter_AlwaysValid() Assert.IsTrue(validateOptionsResult.IsValid); } + [TestMethod] public async Task CommandLineOptions_AlwaysValid() { var provider = new TreeNodeFilterCommandLineOptionsProvider(new TestExtension()); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/AggregatedConfigurationTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/AggregatedConfigurationTests.cs index 7d41698231..925ef3073f 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/AggregatedConfigurationTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/AggregatedConfigurationTests.cs @@ -13,21 +13,24 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class AggregatedConfigurationTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class AggregatedConfigurationTests { private const string ExpectedPath = "a/b/c"; private readonly Mock _testApplicationModuleInfoMock = new(); private readonly Mock _fileSystemMock = new(); - [Arguments(PlatformConfigurationConstants.PlatformResultDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] - public void IndexerTest_DirectoryNotSetAndNoConfigurationProviders_DirectoryIsNull(string key) => Assert.IsNull(new AggregatedConfiguration([], _testApplicationModuleInfoMock.Object, _fileSystemMock.Object)[key]); - - [Arguments(PlatformConfigurationConstants.PlatformResultDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] + [TestMethod] + [DataRow(PlatformConfigurationConstants.PlatformResultDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] + public void IndexerTest_DirectoryNotSetAndNoConfigurationProviders_DirectoryIsNull(string key) + => Assert.IsNull(new AggregatedConfiguration([], _testApplicationModuleInfoMock.Object, _fileSystemMock.Object)[key]); + + [TestMethod] + [DataRow(PlatformConfigurationConstants.PlatformResultDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_DirectoryIsNull(string key) { Mock mockProvider = new(); @@ -36,15 +39,17 @@ public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_Director Assert.IsNull(aggregatedConfiguration[key]); } - [Arguments(PlatformConfigurationConstants.PlatformResultDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] + [TestMethod] + [DataRow(PlatformConfigurationConstants.PlatformResultDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_DirectoryIsNotNull(string key) { AggregatedConfiguration aggregatedConfiguration = new([new FakeConfigurationProvider(ExpectedPath)], _testApplicationModuleInfoMock.Object, _fileSystemMock.Object); Assert.AreEqual(ExpectedPath, aggregatedConfiguration[key]); } + [TestMethod] public void IndexerTest_ResultDirectorySet_DirectoryIsNotNull() { AggregatedConfiguration aggregatedConfiguration = new([], _testApplicationModuleInfoMock.Object, _fileSystemMock.Object); @@ -53,6 +58,7 @@ public void IndexerTest_ResultDirectorySet_DirectoryIsNotNull() Assert.AreEqual(ExpectedPath, aggregatedConfiguration[PlatformConfigurationConstants.PlatformResultDirectory]); } + [TestMethod] public void IndexerTest_CurrentWorkingDirectorySet_DirectoryIsNotNull() { AggregatedConfiguration aggregatedConfiguration = new([], _testApplicationModuleInfoMock.Object, _fileSystemMock.Object); @@ -61,6 +67,7 @@ public void IndexerTest_CurrentWorkingDirectorySet_DirectoryIsNotNull() Assert.AreEqual(ExpectedPath, aggregatedConfiguration[PlatformConfigurationConstants.PlatformCurrentWorkingDirectory]); } + [TestMethod] public void IndexerTest_TestHostWorkingDirectorySet_DirectoryIsNotNull() { AggregatedConfiguration aggregatedConfiguration = new([], _testApplicationModuleInfoMock.Object, _fileSystemMock.Object); @@ -69,6 +76,7 @@ public void IndexerTest_TestHostWorkingDirectorySet_DirectoryIsNotNull() Assert.AreEqual(ExpectedPath, aggregatedConfiguration[PlatformConfigurationConstants.PlatformTestHostWorkingDirectory]); } + [TestMethod] public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_ResultsDirectoryIsNull_GetDirectoryFromCommandLineProvider() { Mock mockTestApplicationModuleInfo = new(); @@ -90,6 +98,7 @@ await aggregatedConfiguration.CheckTestResultsDirectoryOverrideAndCreateItAsync( Assert.AreEqual("a" + Path.DirectorySeparatorChar + "b", aggregatedConfiguration[PlatformConfigurationConstants.PlatformCurrentWorkingDirectory]); } + [TestMethod] public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_ResultsDirectoryIsNull_GetDirectoryFromStore() { Mock mockTestApplicationModuleInfo = new(); @@ -111,6 +120,7 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results Assert.AreEqual("a" + Path.DirectorySeparatorChar + "b", aggregatedConfiguration[PlatformConfigurationConstants.PlatformCurrentWorkingDirectory]); } + [TestMethod] public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_ResultsDirectoryIsNull_GetDefaultDirectory() { Mock mockTestApplicationModuleInfo = new(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationExtensionsTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationExtensionsTests.cs index ead1f42c3d..0727d1d90b 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationExtensionsTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationExtensionsTests.cs @@ -7,14 +7,9 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class ConfigurationExtensionsTests : TestBase +[TestClass] +public sealed class ConfigurationExtensionsTests { - public ConfigurationExtensionsTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - private string GetActualValueFromConfiguration(IConfiguration configuration, string key) => key switch { PlatformConfigurationConstants.PlatformResultDirectory => configuration.GetTestResultDirectory(), @@ -23,9 +18,10 @@ public ConfigurationExtensionsTests(ITestExecutionContext testExecutionContext) _ => throw new ArgumentException("Unsupported key."), }; - [Arguments(PlatformConfigurationConstants.PlatformResultDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] + [TestMethod] + [DataRow(PlatformConfigurationConstants.PlatformResultDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] public void ConfigurationExtensions_TestedMethod_ReturnsExpectedPath(string key) { string expectedPath = Path.Combine("a", "b", "c"); @@ -38,9 +34,10 @@ public void ConfigurationExtensions_TestedMethod_ReturnsExpectedPath(string key) Assert.AreEqual(expectedPath, GetActualValueFromConfiguration(configuration.Object, key)); } - [Arguments(PlatformConfigurationConstants.PlatformResultDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] - [Arguments(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] + [TestMethod] + [DataRow(PlatformConfigurationConstants.PlatformResultDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformCurrentWorkingDirectory)] + [DataRow(PlatformConfigurationConstants.PlatformTestHostWorkingDirectory)] public void ConfigurationExtensions_TestedMethod_ThrowsArgumentNullException(string key) { Mock configuration = new(); @@ -48,6 +45,6 @@ public void ConfigurationExtensions_TestedMethod_ThrowsArgumentNullException(str .Setup(configuration => configuration[key]) .Returns(value: null); - Assert.Throws(() => GetActualValueFromConfiguration(configuration.Object, key)); + Assert.ThrowsException(() => GetActualValueFromConfiguration(configuration.Object, key)); } } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs index 8b516c7269..18faf51a91 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs @@ -13,19 +13,19 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class ConfigurationManagerTests : TestBase +[TestClass] +public sealed class ConfigurationManagerTests { private readonly ServiceProvider _serviceProvider; - public ConfigurationManagerTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public ConfigurationManagerTests() { _serviceProvider = new(); _serviceProvider.AddService(new SystemFileSystem()); } - [ArgumentsProvider(nameof(GetConfigurationValueFromJsonData))] + [TestMethod] + [DynamicData(nameof(GetConfigurationValueFromJsonData), DynamicDataSourceType.Method)] public async ValueTask GetConfigurationValueFromJson(string jsonFileConfig, string key, string? result) { Mock fileSystem = new(); @@ -56,6 +56,7 @@ public async ValueTask GetConfigurationValueFromJson(string jsonFileConfig, stri yield return ("{\"platformOptions\": { \"Array\" : [ {\"Key\" : \"Value\"} , {\"Key\" : 3} ] } }", "platformOptions:Array:1:Key", "3"); } + [TestMethod] public async ValueTask InvalidJson_Fail() { Mock fileSystem = new(); @@ -65,10 +66,11 @@ public async ValueTask InvalidJson_Fail() ConfigurationManager configurationManager = new(fileSystem.Object, testApplicationModuleInfo); configurationManager.AddConfigurationSource(() => new JsonConfigurationSource(testApplicationModuleInfo, fileSystem.Object, null)); - await Assert.ThrowsAsync(() => configurationManager.BuildAsync(null, new CommandLineParseResult(null, new List(), Array.Empty()))); + await Assert.ThrowsAsync(() => configurationManager.BuildAsync(null, new CommandLineParseResult(null, new List(), Array.Empty()))); } - [ArgumentsProvider(nameof(GetConfigurationValueFromJsonData))] + [TestMethod] + [DynamicData(nameof(GetConfigurationValueFromJsonData), DynamicDataSourceType.Method)] public async ValueTask GetConfigurationValueFromJsonWithFileLoggerProvider(string jsonFileConfig, string key, string? result) { byte[] bytes = Encoding.UTF8.GetBytes(jsonFileConfig); @@ -97,6 +99,7 @@ public async ValueTask GetConfigurationValueFromJsonWithFileLoggerProvider(strin loggerMock.Verify(x => x.LogAsync(LogLevel.Trace, It.IsAny(), null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask BuildAsync_EmptyConfigurationSources_ThrowsException() { CurrentTestApplicationModuleInfo testApplicationModuleInfo = new(new SystemEnvironment(), new SystemProcessHandler()); @@ -104,6 +107,7 @@ public async ValueTask BuildAsync_EmptyConfigurationSources_ThrowsException() await Assert.ThrowsAsync(() => configurationManager.BuildAsync(null, new CommandLineParseResult(null, new List(), Array.Empty()))); } + [TestMethod] public async ValueTask BuildAsync_ConfigurationSourcesNotEnabledAsync_ThrowsException() { Mock mockConfigurationSource = new(); @@ -118,6 +122,7 @@ public async ValueTask BuildAsync_ConfigurationSourcesNotEnabledAsync_ThrowsExce mockConfigurationSource.Verify(x => x.IsEnabledAsync(), Times.Once); } + [TestMethod] public async ValueTask BuildAsync_ConfigurationSourceIsAsyncInitializableExtension_InitializeAsyncIsCalled() { Mock mockConfigurationProvider = new(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs index e1cad5c9e3..484bbc5890 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs @@ -5,14 +5,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class CountDownEventTests : TestBase +[TestClass] +public sealed class CountDownEventTests { - public CountDownEventTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task CountDownEvent_WaitAsync_Succeeded() { CountdownEvent countdownEvent = new(3); @@ -36,6 +32,7 @@ public async Task CountDownEvent_WaitAsync_Succeeded() Assert.IsTrue(await waiter1); } + [TestMethod] public async Task CountDownEvent_WaitAsyncCanceled_Succeeded() { CountdownEvent countdownEvent = new(1); @@ -46,6 +43,7 @@ public async Task CountDownEvent_WaitAsyncCanceled_Succeeded() await Assert.ThrowsAsync(async () => await waiter); } + [TestMethod] public async Task CountDownEvent_WaitAsyncCanceledByTimeout_Succeeded() { CountdownEvent countdownEvent = new(1); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/SystemAsyncMonitorTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/SystemAsyncMonitorTests.cs index bba20c5da7..a62f3bb5ed 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/SystemAsyncMonitorTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/SystemAsyncMonitorTests.cs @@ -7,14 +7,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class SystemAsyncMonitorTests : TestBase +[TestClass] +public sealed class SystemAsyncMonitorTests { - public SystemAsyncMonitorTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task AsyncMonitor_ShouldCorrectlyLock() { var asyncSystemMonitor = (SystemAsyncMonitor)new SystemMonitorAsyncFactory().Create(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs index d857372c67..e1c27f56f8 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs @@ -5,27 +5,29 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class TaskExtensionsTests : TestBase +[TestClass] +public sealed class TaskExtensionsTests { - public TaskExtensionsTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - - public async Task TimeoutAfterAsync_Succeeds() => await Assert.ThrowsAsync(async () - => await Task.Delay(TimeSpan.FromSeconds(60)).TimeoutAfterAsync(TimeSpan.FromSeconds(2))); + [TestMethod] + public async Task TimeoutAfterAsync_Succeeds() + => await Assert.ThrowsAsync(async () => + await Task.Delay(TimeSpan.FromSeconds(60)).TimeoutAfterAsync(TimeSpan.FromSeconds(2))); - public async Task TimeoutAfterAsync_CancellationToken_Succeeds() => await Assert.ThrowsAsync(async () => - await Task.Delay(TimeSpan.FromSeconds(60)).TimeoutAfterAsync( - TimeSpan.FromSeconds(30), - new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token)); + [TestMethod] + public async Task TimeoutAfterAsync_CancellationToken_Succeeds() + => await Assert.ThrowsAsync(async () => + await Task.Delay(TimeSpan.FromSeconds(60)).TimeoutAfterAsync( + TimeSpan.FromSeconds(30), + new CancellationTokenSource(TimeSpan.FromSeconds(2)).Token)); - public async Task TimeoutAfterAsync_CancellationTokenNone_Succeeds() => await Assert.ThrowsAsync(async () => - await Task.Delay(TimeSpan.FromSeconds(60)).TimeoutAfterAsync( - TimeSpan.FromSeconds(2), - CancellationToken.None)); + [TestMethod] + public async Task TimeoutAfterAsync_CancellationTokenNone_Succeeds() + => await Assert.ThrowsAsync(async () => + await Task.Delay(TimeSpan.FromSeconds(60)).TimeoutAfterAsync( + TimeSpan.FromSeconds(2), + CancellationToken.None)); + [TestMethod] public async Task CancellationAsync_Cancellation_Succeeds() { CancellationTokenSource cancellationTokenSource = new(); @@ -38,6 +40,7 @@ public async Task CancellationAsync_Cancellation_Succeeds() Assert.AreEqual(cancelToken, exception.CancellationToken); } + [TestMethod] public async Task CancellationAsync_CancellationWithArgument_Succeeds() { CancellationTokenSource cancellationTokenSource = new(); @@ -50,6 +53,7 @@ public async Task CancellationAsync_CancellationWithArgument_Succeeds() Assert.AreEqual(cancelToken, exception.CancellationToken); } + [TestMethod] public async Task CancellationAsync_NonCanceled_Succeeds() { CancellationTokenSource cancellationTokenSource = new(); @@ -57,54 +61,59 @@ public async Task CancellationAsync_NonCanceled_Succeeds() await Task.Delay(TimeSpan.FromSeconds(1), cancelToken).WithCancellationAsync(cancelToken); } + [TestMethod] public async Task CancellationAsync_NonCanceledWithArgument_Succeeds() { CancellationTokenSource cancellationTokenSource = new(); Assert.AreEqual("Hello", await DoSomething().WithCancellationAsync(cancellationTokenSource.Token)); } - public async Task CancellationAsync_ObserveException_Succeeds() => await RetryHelper.RetryAsync( - async () => - { - ManualResetEvent waitException = new(false); - await Assert.ThrowsAsync(async () - => await Task.Run(async () => - { - await Task.Delay(TimeSpan.FromSeconds(10)); - waitException.Set(); - throw new InvalidOperationException(); - }).WithCancellationAsync(new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token)); + [TestMethod] + public async Task CancellationAsync_ObserveException_Succeeds() + => await RetryHelper.RetryAsync( + async () => + { + ManualResetEvent waitException = new(false); + await Assert.ThrowsAsync(async () + => await Task.Run(async () => + { + await Task.Delay(TimeSpan.FromSeconds(10)); + waitException.Set(); + throw new InvalidOperationException(); + }).WithCancellationAsync(new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token)); - waitException.WaitOne(); - await Task.Delay(TimeSpan.FromSeconds(4)); - }, 3, TimeSpan.FromSeconds(3), _ => true); + waitException.WaitOne(); + await Task.Delay(TimeSpan.FromSeconds(4)); + }, 3, TimeSpan.FromSeconds(3), _ => true); - public async Task CancellationAsyncWithReturnValue_ObserveException_Succeeds() => await RetryHelper.RetryAsync( - async () => - { - ManualResetEvent waitException = new(false); - await Assert.ThrowsAsync(async () - => await Task.Run(async () => + [TestMethod] + public async Task CancellationAsyncWithReturnValue_ObserveException_Succeeds() + => await RetryHelper.RetryAsync( + async () => + { + ManualResetEvent waitException = new(false); + await Assert.ThrowsAsync(async () + => await Task.Run(async () => + { + await Task.Delay(TimeSpan.FromSeconds(10)); + try + { + return 2; + } + finally { - await Task.Delay(TimeSpan.FromSeconds(10)); - try - { - return 2; - } - finally - { - waitException.Set(); + waitException.Set(); #pragma warning disable CA2219 // Do not raise exceptions in finally clauses - throw new InvalidOperationException(); + throw new InvalidOperationException(); #pragma warning restore CA2219 // Do not raise exceptions in finally clauses - } - }).WithCancellationAsync(new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token)); + } + }).WithCancellationAsync(new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token)); - waitException.WaitOne(); - await Task.Delay(TimeSpan.FromSeconds(4)); - }, 3, TimeSpan.FromSeconds(3), _ => true); + waitException.WaitOne(); + await Task.Delay(TimeSpan.FromSeconds(4)); + }, 3, TimeSpan.FromSeconds(3), _ => true); - private async Task DoSomething() + private static async Task DoSomething() { await Task.Delay(TimeSpan.FromSeconds(1)); return "Hello"; diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs index 591542bc78..fea23a67d7 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs @@ -11,14 +11,15 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class IPCTests : TestBase +[TestClass] +public sealed class IPCTests { - private readonly ITestExecutionContext _testExecutionContext; + private readonly TestContext _testContext; - public IPCTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) => _testExecutionContext = testExecutionContext; + public IPCTests(TestContext testContext) + => _testContext = testContext; + [TestMethod] public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() { PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N")); @@ -39,9 +40,9 @@ public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() new SystemEnvironment(), new Mock().Object, new SystemTask(), - _testExecutionContext.CancellationToken); + _testContext.CancellationTokenSource.Token); - await singleConnectionNamedPipeServer.WaitConnectionAsync(_testExecutionContext.CancellationToken); + await singleConnectionNamedPipeServer.WaitConnectionAsync(_testContext.CancellationTokenSource.Token); openedPipe.Add(singleConnectionNamedPipeServer); } } @@ -53,7 +54,7 @@ public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() }); NamedPipeClient namedPipeClient1 = new(pipeNameDescription.Name); - await namedPipeClient1.ConnectAsync(_testExecutionContext.CancellationToken); + await namedPipeClient1.ConnectAsync(_testContext.CancellationTokenSource.Token); waitException.Wait(); Assert.AreEqual(1, openedPipe.Count); @@ -82,6 +83,7 @@ public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() pipeNameDescription.Dispose(); } + [TestMethod] public async Task SingleConnectionNamedPipeServer_RequestReplySerialization_Succeeded() { Queue receivedMessages = new(); @@ -103,9 +105,9 @@ public async Task SingleConnectionNamedPipeServer_RequestReplySerialization_Succ manualResetEventSlim.Set(); break; } - catch (OperationCanceledException ct) when (ct.CancellationToken == _testExecutionContext.CancellationToken) + catch (OperationCanceledException ct) when (ct.CancellationToken == _testContext.CancellationTokenSource.Token) { - throw new OperationCanceledException("SingleConnectionNamedPipeServer_RequestReplySerialization_Succeeded cancellation during connect, _testExecutionContext.CancellationToken"); + throw new OperationCanceledException("SingleConnectionNamedPipeServer_RequestReplySerialization_Succeeded cancellation during connect, testContext.CancellationTokenSource.Token"); } catch (OperationCanceledException) { @@ -166,7 +168,8 @@ public async Task SingleConnectionNamedPipeServer_RequestReplySerialization_Succ pipeNameDescription.Dispose(); } - public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() + [TestMethod] + public async Task ConnectionNamedPipeServer_MultipleConnection_Succeeds() { PipeNameDescription pipeNameDescription = NamedPipeServer.GetPipeName(Guid.NewGuid().ToString("N")); @@ -174,17 +177,16 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() for (int i = 0; i < 3; i++) { pipes.Add(new( - pipeNameDescription, - async _ => await Task.FromResult(VoidResponse.CachedInstance), - new SystemEnvironment(), - new Mock().Object, - new SystemTask(), - maxNumberOfServerInstances: 3, - _testExecutionContext.CancellationToken)); + pipeNameDescription, + async _ => await Task.FromResult(VoidResponse.CachedInstance), + new SystemEnvironment(), + new Mock().Object, + new SystemTask(), + maxNumberOfServerInstances: 3, + _testContext.CancellationTokenSource.Token)); } -#pragma warning disable CA1806 // Do not ignore method results - IOException exception = Assert.Throws(() => + IOException exception = Assert.ThrowsException(() => new NamedPipeServer( pipeNameDescription, async _ => await Task.FromResult(VoidResponse.CachedInstance), @@ -192,9 +194,8 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() new Mock().Object, new SystemTask(), maxNumberOfServerInstances: 3, - _testExecutionContext.CancellationToken)); - Assert.Contains("All pipe instances are busy.", exception.Message); -#pragma warning restore CA1806 // Do not ignore method results + _testContext.CancellationTokenSource.Token)); + StringAssert.Contains(exception.Message, "All pipe instances are busy."); List waitConnectionTask = new(); int connectionCompleted = 0; @@ -202,7 +203,7 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() { waitConnectionTask.Add(Task.Run(async () => { - await namedPipeServer.WaitConnectionAsync(_testExecutionContext.CancellationToken); + await namedPipeServer.WaitConnectionAsync(_testContext.CancellationTokenSource.Token); Interlocked.Increment(ref connectionCompleted); })); } @@ -212,7 +213,7 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() { NamedPipeClient namedPipeClient = new(pipeNameDescription.Name); connectedClients.Add(namedPipeClient); - await namedPipeClient.ConnectAsync(_testExecutionContext.CancellationToken); + await namedPipeClient.ConnectAsync(_testContext.CancellationTokenSource.Token); } await Task.WhenAll(waitConnectionTask.ToArray()); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/ProtocolTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/ProtocolTests.cs index 9928d95bff..aae141f46a 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/ProtocolTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/ProtocolTests.cs @@ -6,14 +6,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class ProtocolTests : TestBase +[TestClass] +public sealed class ProtocolTests { - public ProtocolTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void TestResultMessagesSerializeDeserialize() { var success = new SuccessfulTestResultMessage("uid", "displayName", 1, 100, "reason", "standardOutput", "errorOutput", "sessionUid"); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs index e770711541..e5d53c93e6 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/FileLoggerTests.cs @@ -11,8 +11,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class FileLoggerTests : TestBase, IDisposable +[TestClass] +public sealed class FileLoggerTests : IDisposable { private const string LogFolder = "aaa"; private const string LogPrefix = "bbb"; @@ -33,8 +33,7 @@ public class FileLoggerTests : TestBase, IDisposable private readonly Mock _mockFileStreamFactory = new(); private readonly MemoryStream _memoryStream; - public FileLoggerTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public FileLoggerTests() { _mockStream.Setup(x => x.Dispose()); #if NETCOREAPP @@ -46,6 +45,7 @@ public FileLoggerTests(ITestExecutionContext testExecutionContext) _mockStream.Setup(x => x.Stream).Returns(_memoryStream); } + [TestMethod] public void Write_IfMalformedUTF8_ShouldNotCrash() { using TempDirectory tempDirectory = new(nameof(Write_IfMalformedUTF8_ShouldNotCrash)); @@ -60,6 +60,7 @@ public void Write_IfMalformedUTF8_ShouldNotCrash() fileLogger.Log(LogLevel.Trace, "\uD886", null, LoggingExtensions.Formatter, "Category"); } + [TestMethod] public void FileLogger_NullFileSyncFlush_FileStreamCreated() { // First return is to compute the expected file name. It's ok that first time is greater @@ -98,6 +99,7 @@ public void FileLogger_NullFileSyncFlush_FileStreamCreated() Assert.AreEqual(expectedFileName, fileLoggerName); } + [TestMethod] public void FileLogger_NullFileSyncFlush_FileStreamCreationThrows() { // First return is to compute the expected file name. It's ok that first time is greater @@ -111,7 +113,7 @@ public void FileLogger_NullFileSyncFlush_FileStreamCreationThrows() .Throws() .Returns(_mockStream.Object); - Assert.Throws(() => _ = new FileLogger( + Assert.ThrowsException(() => _ = new FileLogger( new(LogFolder, LogPrefix, fileName: null, syncFlush: true), LogLevel.Trace, _mockClock.Object, @@ -121,10 +123,11 @@ public void FileLogger_NullFileSyncFlush_FileStreamCreationThrows() _mockFileStreamFactory.Object)); } - [Arguments(true, true)] - [Arguments(true, false)] - [Arguments(false, true)] - [Arguments(false, false)] + [DataRow(true, true)] + [DataRow(true, false)] + [DataRow(false, true)] + [DataRow(false, false)] + [TestMethod] public void FileLogger_ValidFileName_FileStreamCreatedSuccessfully(bool syncFlush, bool fileExists) { string expectedPath = Path.Combine(LogFolder, FileName); @@ -152,7 +155,8 @@ public void FileLogger_ValidFileName_FileStreamCreatedSuccessfully(bool syncFlus Assert.AreEqual(FileName, fileLoggerName); } - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers))] + [TestMethod] + [DynamicData(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers), DynamicDataSourceType.Method)] public async Task Log_WhenSyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt(LogLevel defaultLogLevel, LogLevel currentLogLevel) { _mockFileSystem.Setup(x => x.Exists(It.IsAny())).Returns(false); @@ -186,7 +190,8 @@ public async Task Log_WhenSyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt } } - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers))] + [TestMethod] + [DynamicData(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers), DynamicDataSourceType.Method)] public async Task Log_WhenAsyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsIt(LogLevel defaultLogLevel, LogLevel currentLogLevel) { _mockFileSystem.Setup(x => x.Exists(It.IsAny())).Returns(false); @@ -219,5 +224,6 @@ public async Task Log_WhenAsyncFlush_StreamWriterIsCalledOnlyWhenLogLevelAllowsI } } - public void Dispose() => _memoryStream.Dispose(); + void IDisposable.Dispose() + => _memoryStream.Dispose(); } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs index e0dc034294..571f312dff 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs @@ -16,6 +16,9 @@ public static IEnumerable GetLogLevels() => typeof(LogLevel).GetEnumValues().Cast(); #endif + public static IEnumerable GetLogLevelsForDynamicData() + => GetLogLevels().Select(x => new object[] { x }); + public static IEnumerable<(LogLevel DefaultLevel, LogLevel CurrentLevel)> GetLogLevelCombinations() { List<(LogLevel, LogLevel)> logLevelCombinations = new(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryTests.cs index 8322b1c830..d257ecf3d4 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryTests.cs @@ -8,16 +8,15 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class LoggerFactoryTests : TestBase +[TestClass] +public sealed class LoggerFactoryTests { private readonly Mock _mockLogger = new(); private readonly Mock _mockMonitor = new(); private readonly Mock _mockLoggerProvider = new(); private readonly ILoggerProvider[] _loggerProviders; - public LoggerFactoryTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public LoggerFactoryTests() { _mockMonitor.Setup(x => x.Lock(It.IsAny())).Returns(new Mock().Object); _mockLoggerProvider.Setup(x => x.CreateLogger(It.IsAny())).Returns(_mockLogger.Object); @@ -28,6 +27,7 @@ public LoggerFactoryTests(ITestExecutionContext testExecutionContext) ]; } + [TestMethod] public void LoggerFactory_LoggerCreatedOnlyOnce() { using LoggerFactory loggerFactory = new(_loggerProviders, LogLevel.Information, _mockMonitor.Object); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerTests.cs index d4be4a9dc2..97852718f0 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerTests.cs @@ -9,8 +9,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class LoggerTests : TestBase +[TestClass] +public sealed class LoggerTests { private static readonly Func Formatter = (state, exception) => @@ -20,8 +20,7 @@ public class LoggerTests : TestBase private readonly Exception _exception = new("TestException"); private readonly Mock _mockLogger = new(); - public LoggerTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public LoggerTests() { _mockLogger.Setup(x => x.Log(It.IsAny(), It.IsAny(), It.IsAny(), Formatter)); _mockLogger.Setup(x => x.LogAsync(It.IsAny(), It.IsAny(), It.IsAny(), Formatter)); @@ -38,14 +37,16 @@ private Logger CreateLogger(LogLevel logLevel) return new Logger(mockLoggerFactory.Object); } - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers))] + [DynamicData(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [TestMethod] public void Logger_CheckEnabled(LogLevel defaultLogLevel, LogLevel currentLogLevel) { Logger logger = CreateLogger(defaultLogLevel); Assert.AreEqual(logger.IsEnabled(currentLogLevel), LogTestHelpers.IsLogEnabled(defaultLogLevel, currentLogLevel)); } - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers))] + [DynamicData(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [TestMethod] public void Logger_Log_FormattedStringIsCorrect(LogLevel defaultLogLevel, LogLevel currentLogLevel) { Logger logger = CreateLogger(defaultLogLevel); @@ -56,7 +57,8 @@ public void Logger_Log_FormattedStringIsCorrect(LogLevel defaultLogLevel, LogLev LogTestHelpers.GetExpectedLogCallTimes(defaultLogLevel, currentLogLevel)); } - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers))] + [DynamicData(nameof(LogTestHelpers.GetLogLevelCombinations), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [TestMethod] public async ValueTask Logger_LogAsync_FormattedStringIsCorrect(LogLevel defaultLogLevel, LogLevel currentLogLevel) { Logger logger = CreateLogger(defaultLogLevel); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingExtensionsTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingExtensionsTests.cs index ac6b5d61bc..194d2c5e80 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingExtensionsTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingExtensionsTests.cs @@ -7,8 +7,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class LoggingExtensionsTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class LoggingExtensionsTest { private const string Message = "Test"; private readonly Exception _exception = new("TestException"); @@ -16,6 +16,7 @@ public class LoggingExtensionsTests(ITestExecutionContext testExecutionContext) // Use strict mock to ensure that only the expected methods are called private readonly Mock _mockLogger = new(MockBehavior.Strict); + [TestMethod] public void LoggerExtensions_LogTrace_CallsLogWithLogLevelTrace() { _mockLogger.Setup(x => x.Log(LogLevel.Trace, Message, null, LoggingExtensions.Formatter)); @@ -23,6 +24,7 @@ public void LoggerExtensions_LogTrace_CallsLogWithLogLevelTrace() _mockLogger.Verify(x => x.Log(LogLevel.Trace, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogDebug_CallsLogWithLogLevelDebug() { _mockLogger.Setup(x => x.Log(LogLevel.Debug, Message, null, LoggingExtensions.Formatter)); @@ -30,6 +32,7 @@ public void LoggerExtensions_LogDebug_CallsLogWithLogLevelDebug() _mockLogger.Verify(x => x.Log(LogLevel.Debug, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogInformation_CallsLogWithLogLevelInformation() { _mockLogger.Setup(x => x.Log(LogLevel.Information, Message, null, LoggingExtensions.Formatter)); @@ -37,6 +40,7 @@ public void LoggerExtensions_LogInformation_CallsLogWithLogLevelInformation() _mockLogger.Verify(x => x.Log(LogLevel.Information, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogWarning_CallsLogWithLogLevelWarning() { _mockLogger.Setup(x => x.Log(LogLevel.Warning, Message, null, LoggingExtensions.Formatter)); @@ -44,6 +48,7 @@ public void LoggerExtensions_LogWarning_CallsLogWithLogLevelWarning() _mockLogger.Verify(x => x.Log(LogLevel.Warning, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogError_CallsLogWithLogLevelError() { _mockLogger.Setup(x => x.Log(LogLevel.Error, Message, null, LoggingExtensions.Formatter)); @@ -51,6 +56,7 @@ public void LoggerExtensions_LogError_CallsLogWithLogLevelError() _mockLogger.Verify(x => x.Log(LogLevel.Error, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogError_CallsLogWithLogLevelErrorAndMessageAndException() { _mockLogger.Setup(x => x.Log(LogLevel.Error, Message, _exception, LoggingExtensions.Formatter)); @@ -58,6 +64,7 @@ public void LoggerExtensions_LogError_CallsLogWithLogLevelErrorAndMessageAndExce _mockLogger.Verify(x => x.Log(LogLevel.Error, Message, _exception, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogError_CallsLogWithLogLevelErrorAndException() { _mockLogger.Setup(x => x.Log(LogLevel.Error, _exception.ToString(), null, LoggingExtensions.Formatter)); @@ -65,6 +72,7 @@ public void LoggerExtensions_LogError_CallsLogWithLogLevelErrorAndException() _mockLogger.Verify(x => x.Log(LogLevel.Error, _exception.ToString(), null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public void LoggerExtensions_LogCritical_CallsLogWithLogLevelCritical() { _mockLogger.Setup(x => x.Log(LogLevel.Critical, Message, null, LoggingExtensions.Formatter)); @@ -72,6 +80,7 @@ public void LoggerExtensions_LogCritical_CallsLogWithLogLevelCritical() _mockLogger.Verify(x => x.Log(LogLevel.Critical, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogTraceAsync_CallsLogAsyncWithLogLevelTrace() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Trace, Message, null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -79,6 +88,7 @@ public async ValueTask LoggerExtensions_LogTraceAsync_CallsLogAsyncWithLogLevelT _mockLogger.Verify(x => x.LogAsync(LogLevel.Trace, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogDebugAsync_CallsLogAsyncWithLogLevelDebug() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Debug, Message, null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -86,6 +96,7 @@ public async ValueTask LoggerExtensions_LogDebugAsync_CallsLogAsyncWithLogLevelD _mockLogger.Verify(x => x.LogAsync(LogLevel.Debug, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogInformationAsync_CallsLogAsyncWithLogLevelInformation() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Information, Message, null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -93,6 +104,7 @@ public async ValueTask LoggerExtensions_LogInformationAsync_CallsLogAsyncWithLog _mockLogger.Verify(x => x.LogAsync(LogLevel.Information, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogWarningAsync_CallsLogAsyncWithLogLevelWarning() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Warning, Message, null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -100,6 +112,7 @@ public async ValueTask LoggerExtensions_LogWarningAsync_CallsLogAsyncWithLogLeve _mockLogger.Verify(x => x.LogAsync(LogLevel.Warning, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogErrorAsync_CallsLogAsyncWithLogLevelError() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Error, Message, null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -107,6 +120,7 @@ public async ValueTask LoggerExtensions_LogErrorAsync_CallsLogAsyncWithLogLevelE _mockLogger.Verify(x => x.LogAsync(LogLevel.Error, Message, null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogErrorAsync_CallsLogAsyncWithLogLevelErrorAndMessageAndException() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Error, Message, _exception, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -114,6 +128,7 @@ public async ValueTask LoggerExtensions_LogErrorAsync_CallsLogAsyncWithLogLevelE _mockLogger.Verify(x => x.LogAsync(LogLevel.Error, Message, _exception, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogErrorAsync_CallsLogAsyncWithLogLevelErrorAndException() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Error, _exception.ToString(), null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); @@ -121,6 +136,7 @@ public async ValueTask LoggerExtensions_LogErrorAsync_CallsLogAsyncWithLogLevelE _mockLogger.Verify(x => x.LogAsync(LogLevel.Error, _exception.ToString(), null, LoggingExtensions.Formatter), Times.Once); } + [TestMethod] public async ValueTask LoggerExtensions_LogCriticalAsync_CallsLogAsyncWithLogLevelCritical() { _mockLogger.Setup(x => x.LogAsync(LogLevel.Critical, Message, null, LoggingExtensions.Formatter)).Returns(Task.CompletedTask); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs index 1db2c78371..687b8fcfe8 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs @@ -5,8 +5,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class NopLoggerTests(ITestExecutionContext testExecutionContext) : TestBase(testExecutionContext) +[TestClass] +public sealed class NopLoggerTests { private static readonly Func Formatter = (state, exception) => @@ -21,18 +21,21 @@ public class NopLoggerTests(ITestExecutionContext testExecutionContext) : TestBa private static int s_formatterCalls; - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevels), typeof(LogTestHelpers))] + [DynamicData(nameof(LogTestHelpers.GetLogLevelsForDynamicData), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [TestMethod] public void NopLogger_CheckDisabled(LogLevel logLevel) => Assert.IsFalse(_nopLogger.IsEnabled(logLevel)); - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevels), typeof(LogTestHelpers))] + [DynamicData(nameof(LogTestHelpers.GetLogLevelsForDynamicData), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [TestMethod] public void NopLogger_Log_NoFormatterCalls(LogLevel logLevel) { _nopLogger.Log(logLevel, Message, _exception, Formatter); Assert.AreEqual(0, s_formatterCalls); } - [ArgumentsProvider(nameof(LogTestHelpers.GetLogLevels), typeof(LogTestHelpers))] + [DynamicData(nameof(LogTestHelpers.GetLogLevelsForDynamicData), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [TestMethod] public async ValueTask NopLogger_LogAsync_NoFormatterCalls(LogLevel logLevel) { await _nopLogger.LogAsync(logLevel, Message, _exception, Formatter); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/AsynchronousMessageBusTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/AsynchronousMessageBusTests.cs index 94af4c458e..727c21ac87 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/AsynchronousMessageBusTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/AsynchronousMessageBusTests.cs @@ -10,14 +10,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class AsynchronousMessageBusTests : TestBase +[TestClass] +public sealed class AsynchronousMessageBusTests { - public AsynchronousMessageBusTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task UnexpectedTypePublished_ShouldFail() { MessageBusProxy proxy = new(); @@ -37,6 +33,7 @@ public async Task UnexpectedTypePublished_ShouldFail() await Assert.ThrowsAsync(proxy.DrainDataAsync); } + [TestMethod] public async Task DrainDataAsync_Loop_ShouldFail() { MessageBusProxy proxy = new(); @@ -59,7 +56,7 @@ public async Task DrainDataAsync_Loop_ShouldFail() } catch (InvalidOperationException ex) { - Assert.That(ex.Message.Contains("Publisher/Consumer loop detected during the drain after")); + StringAssert.Contains(ex.Message, "Publisher/Consumer loop detected during the drain after"); } // Prevent loop to continue @@ -67,6 +64,7 @@ public async Task DrainDataAsync_Loop_ShouldFail() consumerB.StopConsume(); } + [TestMethod] public async Task MessageBus_WhenConsumerProducesAndConsumesTheSameType_ShouldNotConsumeWhatProducedByItself() { MessageBusProxy proxy = new(); @@ -90,13 +88,14 @@ public async Task MessageBus_WhenConsumerProducesAndConsumesTheSameType_ShouldNo await proxy.DrainDataAsync(); // assert - Assert.AreEqual(consumerA.ConsumedData.Count, 1); - Assert.AreEqual(consumerA.ConsumedData[0], consumerBData); + Assert.AreEqual(1, consumerA.ConsumedData.Count); + Assert.AreEqual(consumerBData, consumerA.ConsumedData[0]); - Assert.AreEqual(consumerB.ConsumedData.Count, 1); - Assert.AreEqual(consumerB.ConsumedData[0], consumerAData); + Assert.AreEqual(1, consumerB.ConsumedData.Count); + Assert.AreEqual(consumerAData, consumerB.ConsumedData[0]); } + [TestMethod] public async Task Consumers_ConsumeData_ShouldNotMissAnyPayload() { int totalConsumers = Environment.ProcessorCount; diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/PropertyBagTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/PropertyBagTests.cs index 0dfb5466ae..12f4ad6b23 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/PropertyBagTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/PropertyBagTests.cs @@ -5,14 +5,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class PropertyBagTests : TestBase +[TestClass] +public sealed class PropertyBagTests { - public PropertyBagTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void Ctors_CorrectlyInit() { PropertyBag property = new([new DummyProperty(), PassedTestNodeStateProperty.CachedInstance]); @@ -24,18 +20,21 @@ public void Ctors_CorrectlyInit() Assert.IsNotNull(property._property); } + [TestMethod] public void Ctors_With_WrongInit_ShouldFail() { - Assert.Throws(() => _ = new PropertyBag([new DummyProperty(), PassedTestNodeStateProperty.CachedInstance, PassedTestNodeStateProperty.CachedInstance])); - Assert.Throws(() => _ = new PropertyBag(new IProperty[] { new DummyProperty(), PassedTestNodeStateProperty.CachedInstance, PassedTestNodeStateProperty.CachedInstance }.AsEnumerable())); + Assert.ThrowsException(() => _ = new PropertyBag([new DummyProperty(), PassedTestNodeStateProperty.CachedInstance, PassedTestNodeStateProperty.CachedInstance])); + Assert.ThrowsException(() => _ = new PropertyBag(new IProperty[] { new DummyProperty(), PassedTestNodeStateProperty.CachedInstance, PassedTestNodeStateProperty.CachedInstance }.AsEnumerable())); } + [TestMethod] public void Counts_ShouldBe_Correct() { PropertyBag property = new([new DummyProperty(), new DummyProperty(), PassedTestNodeStateProperty.CachedInstance]); Assert.AreEqual(3, property.Count); } + [TestMethod] public void AddGet_Of_TestNodeStateProperty_Succed() { PropertyBag property = new(); @@ -51,21 +50,24 @@ public void AddGet_Of_TestNodeStateProperty_Succed() Assert.AreEqual(1, property.OfType().Length); } + [TestMethod] public void Add_Of_TestNodeStateProperty_More_Than_One_Time_Fail() { PropertyBag property = new(); property.Add(PassedTestNodeStateProperty.CachedInstance); - Assert.Throws(() => property.Add(PassedTestNodeStateProperty.CachedInstance)); + Assert.ThrowsException(() => property.Add(PassedTestNodeStateProperty.CachedInstance)); } + [TestMethod] public void Add_Same_Instance_More_Times_Fail() { PropertyBag property = new(); DummyProperty dummyProperty = new(); property.Add(dummyProperty); - Assert.Throws(() => property.Add(dummyProperty)); + Assert.ThrowsException(() => property.Add(dummyProperty)); } + [TestMethod] public void Any_Should_Return_CorrectBoolean() { PropertyBag property = new(); @@ -77,6 +79,7 @@ public void Any_Should_Return_CorrectBoolean() Assert.IsTrue(property.Any()); } + [TestMethod] public void SingleOrDefault_Should_Return_CorrectObject() { PropertyBag property = new(); @@ -89,9 +92,10 @@ public void SingleOrDefault_Should_Return_CorrectObject() Assert.IsNull(property.SingleOrDefault()); property.Add(new DummyProperty()); - Assert.Throws(() => property.SingleOrDefault()); + Assert.ThrowsException(property.SingleOrDefault); } + [TestMethod] public void Single_Should_Return_CorrectObject() { PropertyBag property = new(); @@ -101,12 +105,13 @@ public void Single_Should_Return_CorrectObject() Assert.AreEqual(PassedTestNodeStateProperty.CachedInstance, property.Single()); Assert.AreEqual(prop, property.Single()); - Assert.Throws(() => property.Single()); + Assert.ThrowsException(property.Single); property.Add(new DummyProperty()); - Assert.Throws(() => property.Single()); + Assert.ThrowsException(property.Single); } + [TestMethod] public void OfType_Should_Return_CorrectObject() { PropertyBag property = new(); @@ -118,6 +123,7 @@ public void OfType_Should_Return_CorrectObject() Assert.AreEqual(2, property.OfType().Length); } + [TestMethod] public void AsEnumerable_Should_Return_CorrectItems() { PropertyBag property = new(); @@ -135,7 +141,7 @@ public void AsEnumerable_Should_Return_CorrectItems() list.Remove(prop); } - Assert.IsEmpty(list); + Assert.AreEqual(0, list.Count); list = property.AsEnumerable().ToList(); foreach (IProperty prop in property) @@ -143,16 +149,17 @@ public void AsEnumerable_Should_Return_CorrectItems() list.Remove(prop); } - Assert.IsEmpty(list); + Assert.AreEqual(0, list.Count); } + [TestMethod] public void EmptyProperties_Should_NotFail() { PropertyBag property = new(); Assert.AreEqual(0, property.Count); Assert.IsFalse(property.Any()); Assert.IsNull(property.SingleOrDefault()); - Assert.Throws(() => property.Single()); + Assert.ThrowsException(property.Single); Assert.AreEqual(0, property.OfType().Length); Assert.AreEqual(0, property.AsEnumerable().Count()); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/TestNodeUidTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/TestNodeUidTests.cs index 10d6c1827e..6a57d3b664 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/TestNodeUidTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Messages/TestNodeUidTests.cs @@ -1,47 +1,39 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using FrameworkTestNodeUid = Microsoft.Testing.Internal.Framework.TestNodeUid; - using TestNodeUid = Microsoft.Testing.Platform.Extensions.Messages.TestNodeUid; namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class TestNodeUidTests : TestBase +[TestClass] +public sealed class TestNodeUidTests { - public TestNodeUidTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void TestNodeUid_EqualityChecks_ShouldWorkAsExpected() { TestNodeUid testNodeUid = "TestNodeUid"; string testNodeUidString = testNodeUid; Assert.AreEqual(new TestNodeUid("TestNodeUid"), testNodeUid); - Assert.IsTrue(new FrameworkTestNodeUid("TestNodeUid") == "TestNodeUid"); - Assert.IsTrue(testNodeUid == "TestNodeUid"); - Assert.IsTrue(testNodeUid != "TestNodeUid2"); - Assert.IsTrue(testNodeUidString == testNodeUid); + Assert.AreEqual("TestNodeUid", testNodeUid); + Assert.AreNotEqual("TestNodeUid2", testNodeUid); + Assert.AreEqual(testNodeUidString, testNodeUid); } + [TestMethod] public void TestNodeUid_NullValue_ShouldFail() { -#pragma warning disable CS0219 // Variable is assigned but its value is never used // This won't fail, TestNodeUid is a record (not a record struct) and assigning null is a compile time check // not a runtime check. No construction of the object is happening, so we won't throw. // Assert.Throw(() => { TestNodeUid testNode = null!; }); // Implicit conversion from a null, empty or whitespace string should throw. - Assert.Throws(() => { TestNodeUid testNode = (string)null!; }); - Assert.Throws(() => { TestNodeUid testNode = string.Empty; }); - Assert.Throws(() => { TestNodeUid testNode = " "; }); + Assert.ThrowsException(() => { TestNodeUid testNode = (string)null!; }); + Assert.ThrowsException(() => { TestNodeUid testNode = string.Empty; }); + Assert.ThrowsException(() => { TestNodeUid testNode = " "; }); // Providing null, empty, or whitespace id should throw. - Assert.Throws(() => { TestNodeUid testNode = new(null!); }); - Assert.Throws(() => { TestNodeUid testNode = new(string.Empty); }); - Assert.Throws(() => { TestNodeUid testNode = new(" "); }); -#pragma warning restore CS0219 // Variable is assigned but its value is never used + Assert.ThrowsException(() => { TestNodeUid testNode = new(null!); }); + Assert.ThrowsException(() => { TestNodeUid testNode = new(string.Empty); }); + Assert.ThrowsException(() => { TestNodeUid testNode = new(" "); }); } } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj index 5ff2e65fc9..770d8063a6 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj @@ -1,9 +1,9 @@ - + $(MicrosoftTestingTargetFrameworks);net462 false - true + true Exe @@ -21,10 +21,6 @@ - - - - diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TargetFrameworkParserTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TargetFrameworkParserTests.cs index 1f3ac7a5b2..d597da8847 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TargetFrameworkParserTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TargetFrameworkParserTests.cs @@ -5,37 +5,35 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class TargetFrameworkParserTests : TestBase +[TestClass] +public sealed class TargetFrameworkParserTests { - public TargetFrameworkParserTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - // known 2 digit versions - [Arguments(".NET Framework 4.7.0", "net47")] - [Arguments(".NET Framework 4.8.0", "net48")] + [DataRow(".NET Framework 4.7.0", "net47")] + [DataRow(".NET Framework 4.8.0", "net48")] // known 3 digit versions - [Arguments(".NET Framework 4.6.2", "net462")] - [Arguments(".NET Framework 4.7.1", "net471")] - [Arguments(".NET Framework 4.7.2", "net472")] - [Arguments(".NET Framework 4.8.1", "net481")] + [DataRow(".NET Framework 4.6.2", "net462")] + [DataRow(".NET Framework 4.7.1", "net471")] + [DataRow(".NET Framework 4.7.2", "net472")] + [DataRow(".NET Framework 4.8.1", "net481")] // other - [Arguments(".NET Framework 4.6.3", "net46")] - [Arguments(".NET Framework 4.8.9", "net48")] + [DataRow(".NET Framework 4.6.3", "net46")] + [DataRow(".NET Framework 4.8.9", "net48")] + [TestMethod] public void ParseNETFramework(string longName, string expectedShortName) => Assert.AreEqual(expectedShortName, TargetFrameworkParser.GetShortTargetFramework(longName)); - [Arguments(".NET Core 3.1.0", "netcoreapp3.1")] + [DataRow(".NET Core 3.1.0", "netcoreapp3.1")] + [TestMethod] public void ParseNETCore(string longName, string expectedShortName) => Assert.AreEqual(expectedShortName, TargetFrameworkParser.GetShortTargetFramework(longName)); - [Arguments(".NET 6.0.0", "net6.0")] - [Arguments(".NET 8.0.0", "net8.0")] - [Arguments(".NET 10.0.0", "net10.0")] + [DataRow(".NET 6.0.0", "net6.0")] + [DataRow(".NET 8.0.0", "net8.0")] + [DataRow(".NET 10.0.0", "net10.0")] + [TestMethod] public void ParseNET(string longName, string expectedShortName) => Assert.AreEqual(expectedShortName, TargetFrameworkParser.GetShortTargetFramework(longName)); } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs index d7bbe0f104..221fb03524 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs @@ -9,14 +9,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class TerminalTestReporterTests : TestBase +[TestClass] +public sealed class TerminalTestReporterTests { - public TerminalTestReporterTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void AppendStackFrameFormatsStackTraceLineCorrectly() { var terminal = new StringBuilderTerminal(); @@ -34,30 +30,31 @@ public void AppendStackFrameFormatsStackTraceLineCorrectly() TerminalTestReporter.AppendStackFrame(terminal, firstStackTraceLine); #if NETCOREAPP - Assert.Contains(" at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly() in ", terminal.Output); + StringAssert.Contains(terminal.Output, " at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly() in "); #else - Assert.Contains(" at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly()", terminal.Output); + StringAssert.Contains(terminal.Output, " at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly()"); #endif // Line number without the respective file - Assert.That(!terminal.Output.ToString().Contains(" :0")); + Assert.IsFalse(terminal.Output.ToString().Contains(" :0")); } // Code with line when we have symbols - [Arguments( + [DataRow( " at TestingPlatformEntryPoint.Main(String[]) in /_/TUnit.TestProject/obj/Release/net8.0/osx-x64/TestPlatformEntryPoint.cs:line 16", $" at TestingPlatformEntryPoint.Main(String[]) in /_/TUnit.TestProject/obj/Release/net8.0/osx-x64/TestPlatformEntryPoint.cs:16")] // code without line when we don't have symbols - [Arguments( + [DataRow( " at TestingPlatformEntryPoint.
(String[])", " at TestingPlatformEntryPoint.
(String[])")] // stack trace when published as NativeAOT - [Arguments( + [DataRow( " at BenchmarkTest.ExceptionThrower.d__2.MoveNext() + 0x9d", " at BenchmarkTest.ExceptionThrower.d__2.MoveNext() + 0x9d")] // spanners that we want to keep, to not lose information - [Arguments( + [DataRow( "--- End of stack trace from previous location ---", " --- End of stack trace from previous location ---")] + [TestMethod] public void StackTraceRegexCapturesLines(string stackTraceLine, string expected) { var terminal = new StringBuilderTerminal(); @@ -69,6 +66,7 @@ public void StackTraceRegexCapturesLines(string stackTraceLine, string expected) Assert.AreEqual(expected, terminal.Output); } + [TestMethod] public void OutputFormattingIsCorrect() { var stringBuilderConsole = new StringBuilderConsole(); @@ -167,6 +165,7 @@ Oh no! Assert.AreEqual(expected, ShowEscape(output)); } + [TestMethod] public void OutputProgressFrameIsCorrect() { var stringBuilderConsole = new StringBuilderConsole(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Program.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Program.cs index 3c5b97f952..ee46862285 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Program.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Program.cs @@ -1,10 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Diagnostics; +using System.Reflection; using Microsoft.Testing.Extensions; -using Microsoft.Testing.Internal.Framework.Configurations; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] // Opt-out telemetry Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1"); @@ -12,7 +14,8 @@ // DebuggerUtility.AttachVSToCurrentProcess(); ITestApplicationBuilder builder = await TestApplication.CreateBuilderAsync(args); -builder.AddTestFramework(new TestFrameworkConfiguration(Debugger.IsAttached ? 1 : Environment.ProcessorCount), new Microsoft.Testing.Platform.UnitTests.SourceGeneratedTestNodesBuilder()); +builder.AddMSTest(() => [Assembly.GetEntryAssembly()!]); + #if ENABLE_CODECOVERAGE builder.AddCodeCoverageProvider(); #endif diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Properties/launchSettings.json b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Properties/launchSettings.json index f90979f3cd..3fcf329603 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Properties/launchSettings.json +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Microsoft.Testing.Platform.UnitTests": { "commandName": "Project", - "commandLineArgs": "--treenode-filter /*/*/*/**", + "commandLineArgs": "", "environmentVariables": { //"TESTINGPLATFORM_HOTRELOAD_ENABLED": "1" } diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Requests/TreeNodeFilterTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Requests/TreeNodeFilterTests.cs index 49523583b0..facd2f354b 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Requests/TreeNodeFilterTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Requests/TreeNodeFilterTests.cs @@ -7,14 +7,10 @@ #pragma warning disable TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class TreeNodeFilterTests : TestBase +[TestClass] +public sealed class TreeNodeFilterTests { - public TreeNodeFilterTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void MatchAllFilter_MatchesAnyPath() { TreeNodeFilter filter = new("/**"); @@ -22,16 +18,20 @@ public void MatchAllFilter_MatchesAnyPath() Assert.IsTrue(filter.MatchesFilter("/Path/Of/The/Test", new PropertyBag())); } + [TestMethod] public void MatchAllFilter_MatchesSubpaths() { TreeNodeFilter filter = new("/Path/**"); Assert.IsTrue(filter.MatchesFilter("/Path/Of/The/Test", new PropertyBag())); } - public void MatchAllFilter_Invalid() => Assert.Throws(() => _ = new TreeNodeFilter("/A(&B)")); + [TestMethod] + public void MatchAllFilter_Invalid() => Assert.ThrowsException(() => _ = new TreeNodeFilter("/A(&B)")); - public void MatchAllFilter_DoNotAllowInMiddleOfFilter() => Assert.Throws(() => _ = new TreeNodeFilter("/**/Path")); + [TestMethod] + public void MatchAllFilter_DoNotAllowInMiddleOfFilter() => Assert.ThrowsException(() => _ = new TreeNodeFilter("/**/Path")); + [TestMethod] public void MatchWildcard_MatchesSubstrings() { TreeNodeFilter filter = new("/*.UnitTests"); @@ -40,6 +40,7 @@ public void MatchWildcard_MatchesSubstrings() Assert.IsFalse(filter.MatchesFilter("/ProjectB.FunctionalTests", new PropertyBag())); } + [TestMethod] public void EscapeSequences_SupportsWildcard() { TreeNodeFilter filter = new("/*.\\*UnitTests"); @@ -48,6 +49,7 @@ public void EscapeSequences_SupportsWildcard() Assert.IsFalse(filter.MatchesFilter("/ProjectB.AUnitTests", new PropertyBag())); } + [TestMethod] public void EscapeSequences_SupportsParentheses() { TreeNodeFilter filter = new("/*.\\(UnitTests\\)"); @@ -56,8 +58,10 @@ public void EscapeSequences_SupportsParentheses() Assert.IsFalse(filter.MatchesFilter("/ProjectB.(UnitTests", new PropertyBag())); } - public void EscapeSequences_ThrowsIfLastCharIsAnEscapeChar() => Assert.Throws(() => _ = new TreeNodeFilter("/*.\\(UnitTests\\)\\")); + [TestMethod] + public void EscapeSequences_ThrowsIfLastCharIsAnEscapeChar() => Assert.ThrowsException(() => _ = new TreeNodeFilter("/*.\\(UnitTests\\)\\")); + [TestMethod] public void OrExpression_WorksForLiteralStrings() { TreeNodeFilter filter = new("/A|B"); @@ -66,6 +70,7 @@ public void OrExpression_WorksForLiteralStrings() Assert.IsFalse(filter.MatchesFilter("/C", new PropertyBag())); } + [TestMethod] public void AndExpression() { TreeNodeFilter filter = new("/(*.UnitTests)&(*ProjectB*)"); @@ -75,6 +80,7 @@ public void AndExpression() Assert.IsFalse(filter.MatchesFilter("/ProjectC.UnitTests.SomeExtension", new PropertyBag())); } + [TestMethod] public void Parentheses_EnsuresOrdering() { TreeNodeFilter filter = new("/((*.UnitTests)&(*ProjectB*))|C"); @@ -86,8 +92,11 @@ public void Parentheses_EnsuresOrdering() Assert.IsFalse(filter.MatchesFilter("/C.UnitTests", new PropertyBag())); } - public void Parenthesis_DisallowSeparatorInside() => Assert.Throws(() => _ = new TreeNodeFilter("/(A/B)")); + [TestMethod] + public void Parenthesis_DisallowSeparatorInside() + => Assert.ThrowsException(() => new TreeNodeFilter("/(A/B)")); + [TestMethod] public void Parameters_PropertyCheck() { TreeNodeFilter filter = new("/*.UnitTests[Tag=Fast]"); @@ -96,18 +105,27 @@ public void Parameters_PropertyCheck() Assert.IsFalse(filter.MatchesFilter("/ProjectB.UnitTests", new PropertyBag())); } - public void Parameters_DisallowAtStart() => Assert.Throws(() => _ = new TreeNodeFilter("/[Tag=Fast]")); + [TestMethod] + public void Parameters_DisallowAtStart() + => Assert.ThrowsException(() => _ = new TreeNodeFilter("/[Tag=Fast]")); - public void Parameters_DisallowEmpty() => Assert.Throws(() => _ = new TreeNodeFilter("/Path[]")); + [TestMethod] + public void Parameters_DisallowEmpty() + => Assert.ThrowsException(() => _ = new TreeNodeFilter("/Path[]")); - public void Parameters_DisallowMultiple() => Assert.Throws(() => _ = new TreeNodeFilter("/Path[Prop=2][Prop=B]")); + [TestMethod] + public void Parameters_DisallowMultiple() + => Assert.ThrowsException(() => _ = new TreeNodeFilter("/Path[Prop=2][Prop=B]")); - public void Parameters_DisallowNested() => Assert.Throws(() => _ = new TreeNodeFilter("/Path[X=[Y=1]]")); + [TestMethod] + public void Parameters_DisallowNested() + => Assert.ThrowsException(() => _ = new TreeNodeFilter("/Path[X=[Y=1]]")); - [Arguments("/A/B", "/A/B", true)] - [Arguments("/A/B", "/A%2FB", false)] - [Arguments("/A%2FB", "/A/B", false)] - [Arguments("/A%2FB", "/A%2FB", true)] + [DataRow("/A/B", "/A/B", true)] + [DataRow("/A/B", "/A%2FB", false)] + [DataRow("/A%2FB", "/A/B", false)] + [DataRow("/A%2FB", "/A%2FB", true)] + [TestMethod] public void TestNodeFilterNeedsUrlEncodingOfSlashes(string filter, string nodePath, bool isMatched) { TreeNodeFilter filterInstance = new(filter); @@ -123,14 +141,15 @@ public void TestNodeFilterNeedsUrlEncodingOfSlashes(string filter, string nodePa } } - [Arguments("/A/B[ValueWithSlash=Some/thing]", "/A/B", true)] - [Arguments("/A/B[ValueWithSlash=Some%2Fthing]", "/A/B", false)] - [Arguments("/A/B[Other/thing=KeyWithSlash]", "/A/B", true)] - [Arguments("/A/B[Other%2Fthing=KeyWithSlash]", "/A/B", false)] - [Arguments("/A%2FB[ValueWithSlash=Some/thing]", "/A%2FB", true)] - [Arguments("/A%2FB[ValueWithSlash=Some%2Fthing]", "/A%2FB", false)] - [Arguments("/A%2FB[Other/thing=KeyWithSlash]", "/A%2FB", true)] - [Arguments("/A%2FB[Other%2Fthing=KeyWithSlash]", "/A%2FB", false)] + [DataRow("/A/B[ValueWithSlash=Some/thing]", "/A/B", true)] + [DataRow("/A/B[ValueWithSlash=Some%2Fthing]", "/A/B", false)] + [DataRow("/A/B[Other/thing=KeyWithSlash]", "/A/B", true)] + [DataRow("/A/B[Other%2Fthing=KeyWithSlash]", "/A/B", false)] + [DataRow("/A%2FB[ValueWithSlash=Some/thing]", "/A%2FB", true)] + [DataRow("/A%2FB[ValueWithSlash=Some%2Fthing]", "/A%2FB", false)] + [DataRow("/A%2FB[Other/thing=KeyWithSlash]", "/A%2FB", true)] + [DataRow("/A%2FB[Other%2Fthing=KeyWithSlash]", "/A%2FB", false)] + [TestMethod] public void PropertiesDoNotNeedUrlEncodingOfSlashes(string filter, string nodePath, bool isMatched) { TreeNodeFilter filterInstance = new(filter); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs index 67cdcf857f..5f7440bc80 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs @@ -3,6 +3,8 @@ #pragma warning disable TPEXP // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. +using System.Reflection; + using Microsoft.Testing.Platform.Extensions.Messages; using Microsoft.Testing.Platform.ServerMode; @@ -11,19 +13,23 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class FormatterUtilitiesTests : TestBase +[TestClass] +public sealed class FormatterUtilitiesTests { private readonly IMessageFormatter _formatter = FormatterUtilities.CreateFormatter(); - public FormatterUtilitiesTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) => + public static IEnumerable SerializerTypesForDynamicData + => SerializerUtilities.SerializerTypes.Select(x => new object[] { x }); + + public FormatterUtilitiesTests() + => #if NETCOREAPP Assert.AreEqual("System.Text.Json", _formatter.Id); #else Assert.AreEqual("Jsonite", _formatter.Id); #endif + [TestMethod] public void CanDeserializeTaskResponse() { #pragma warning disable SA1009 // Closing parenthesis should be spaced correctly @@ -44,11 +50,11 @@ public void CanDeserializeTaskResponse() var response = (ResponseMessage)msg; Assert.AreEqual(1, response.Id); - Assert.AreEqual(null, response.Result); + Assert.IsNull(response.Result); } - [ArgumentsProvider(memberName: nameof(SerializerUtilities.SerializerTypes), memberType: typeof(SerializerUtilities), - TestArgumentsEntryProviderMethodName = nameof(FormatSerializerTypes))] + [DynamicData(nameof(SerializerTypesForDynamicData), DynamicDataDisplayName = nameof(FormatSerializerTypes))] + [TestMethod] public async Task SerializeDeserialize_Succeed(Type type) { object instanceToSerialize = CreateInstance(type); @@ -71,8 +77,9 @@ public async Task SerializeDeserialize_Succeed(Type type) static bool HasCustomDeserializeAssert(Type type) => type == typeof(TestNode); } - [Arguments(typeof(DiscoverRequestArgs))] - [Arguments(typeof(RunRequestArgs))] + [DataRow(typeof(DiscoverRequestArgs))] + [DataRow(typeof(RunRequestArgs))] + [TestMethod] public void DeserializeSpecificTypes(Type type) { string json = CreateSerializedInstance(type); @@ -93,7 +100,7 @@ public void DeserializeSpecificTypes(Type type) } else { - Assert.AreEqual(actual, expected); + Assert.AreEqual(expected, actual); } } } @@ -127,7 +134,10 @@ private static void CustomAssert(Type type, object instanceDeserialized, object } } - internal static TestArgumentsEntry FormatSerializerTypes(TestArgumentsContext testArgumentsContext) => new((Type)testArgumentsContext.Arguments, ((Type)testArgumentsContext.Arguments).Name); + public static string? FormatSerializerTypes(MethodInfo methodInfo, object?[]? data) + => data is not null + ? (data[0] as Type)?.Name + : null; private static void AssertSerialize(Type type, string instanceSerialized) { diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsonTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsonTests.cs index bae1ad7d57..cfa9e68ac5 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsonTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsonTests.cs @@ -9,13 +9,12 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class JsonTests : TestBase +[TestClass] +public sealed class JsonTests { private readonly Json _json; - public JsonTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public JsonTests() { Dictionary serializers = new(); Dictionary deserializers = new(); @@ -36,6 +35,7 @@ public JsonTests(ITestExecutionContext testExecutionContext) _json = new Json(serializers, deserializers); } + [TestMethod] public async Task Serialize_TestNodeAsync() { // Arrange @@ -45,7 +45,7 @@ public async Task Serialize_TestNodeAsync() { DisplayName = "test", Properties = bag, - Uid = new Extensions.Messages.TestNodeUid("11111"), + Uid = new TestNodeUid("11111"), }; // Act @@ -55,6 +55,7 @@ public async Task Serialize_TestNodeAsync() Assert.AreEqual("""{"uid":"11111","display-name":"test","hello":"my friend","node-type":"group"}""", actual); } + [TestMethod] public async Task Serialize_Array() { // Arrange @@ -67,6 +68,7 @@ public async Task Serialize_Array() Assert.AreEqual("[1,2,3]", actual); } + [TestMethod] public async Task Serialize_DateTimeOffset() { // Arrange @@ -79,6 +81,7 @@ public async Task Serialize_DateTimeOffset() Assert.AreEqual("2023-01-01T01:01:01.0010000+00:00", actual.Trim('"')); } + [TestMethod] public async Task Serialize_ArrayOfObjects() { // Arrange @@ -113,6 +116,7 @@ public async Task Serialize_ArrayOfObjects() Assert.AreEqual("""[{"name":"Thomas","children":[{"name":"Ruth","children":null}]},[2],3]""", actual); } + [TestMethod] public void DeserializePerson() { // Arrange @@ -137,6 +141,7 @@ public void DeserializePerson() Assert.IsNull(actual.Children![0].Children); } + [TestMethod] public void DeserializePersonList() { // Arrange diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsoniteTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsoniteTests.cs index cee4678ebf..853256dc7f 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsoniteTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/JsoniteTests.cs @@ -3,14 +3,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class JsoniteTests : TestBase +[TestClass] +public sealed class JsoniteTests { - public JsoniteTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void Serialize_DateTimeOffset() { #if !NETCOREAPP diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs index 71054ee0d7..e1703f6e8d 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs @@ -15,8 +15,8 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class ServerDataConsumerServiceTests : TestBase, IAsyncCleanable, IDisposable +[TestClass] +public sealed class ServerDataConsumerServiceTests : IDisposable { private readonly PerRequestServerDataConsumer _service; private readonly ServiceProvider _serviceProvider = new(); @@ -25,13 +25,13 @@ public sealed class ServerDataConsumerServiceTests : TestBase, IAsyncCleanable, private readonly Guid _runId = Guid.NewGuid(); - public ServerDataConsumerServiceTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public ServerDataConsumerServiceTests() { _serviceProvider.TryAddService(new PerRequestTestSessionContext(CancellationToken.None, CancellationToken.None)); _service = new PerRequestServerDataConsumer(_serviceProvider, _serverTestHost.Object, _runId, _task.Object); } + [TestMethod] public async Task ConsumeAsync_WithSessionFileArtifact() { SessionFileArtifact sessionFileArtifact = new(new SessionUid("1"), new FileInfo("file"), "name", "description"); @@ -55,6 +55,7 @@ public async Task ConsumeAsync_WithSessionFileArtifact() Assert.AreEqual(expected[0].Description, actual[0].Description); } + [TestMethod] public async Task ConsumeAsync_WithTestNodeUpdatedMessage() { TestNodeUpdateMessage testNode = new(new SessionUid("1"), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty }); @@ -66,6 +67,7 @@ public async Task ConsumeAsync_WithTestNodeUpdatedMessage() Assert.AreEqual(0, actual.Count); } + [TestMethod] public void PopulateTestNodeStatistics_WithMissingNodeType() { TestNodeUpdateMessage testNode = new(new SessionUid("1"), new TestNode { Uid = new TestNodeUid("test()"), DisplayName = string.Empty }); @@ -73,11 +75,12 @@ public void PopulateTestNodeStatistics_WithMissingNodeType() _service.PopulateTestNodeStatistics(testNode); TestNodeStatistics statistics = _service.GetTestNodeStatistics(); - Assert.AreEqual(statistics.TotalDiscoveredTests, 0); - Assert.AreEqual(statistics.TotalPassedTests, 0); - Assert.AreEqual(statistics.TotalFailedTests, 0); + Assert.AreEqual(0, statistics.TotalDiscoveredTests); + Assert.AreEqual(0, statistics.TotalPassedTests); + Assert.AreEqual(0, statistics.TotalFailedTests); } + [TestMethod] public void PopulateTestNodeStatistics_WithDuplicateDiscoveredEvents() { PropertyBag properties = new( @@ -89,11 +92,12 @@ public void PopulateTestNodeStatistics_WithDuplicateDiscoveredEvents() _service.PopulateTestNodeStatistics(testNode); TestNodeStatistics statistics = _service.GetTestNodeStatistics(); - Assert.AreEqual(statistics.TotalDiscoveredTests, 1); - Assert.AreEqual(statistics.TotalPassedTests, 0); - Assert.AreEqual(statistics.TotalFailedTests, 0); + Assert.AreEqual(1, statistics.TotalDiscoveredTests); + Assert.AreEqual(0, statistics.TotalPassedTests); + Assert.AreEqual(0, statistics.TotalFailedTests); } + [TestMethod] public void PopulateTestNodeStatistics_WithDiscoveredAndPassedEventsForSameUid() { PropertyBag properties = new( @@ -110,11 +114,12 @@ public void PopulateTestNodeStatistics_WithDiscoveredAndPassedEventsForSameUid() _service.PopulateTestNodeStatistics(otherTestNode); TestNodeStatistics statistics = _service.GetTestNodeStatistics(); - Assert.AreEqual(statistics.TotalDiscoveredTests, 1); - Assert.AreEqual(statistics.TotalPassedTests, 1); - Assert.AreEqual(statistics.TotalFailedTests, 0); + Assert.AreEqual(1, statistics.TotalDiscoveredTests); + Assert.AreEqual(1, statistics.TotalPassedTests); + Assert.AreEqual(0, statistics.TotalFailedTests); } + [TestMethod] public void PopulateTestNodeStatistics_WithDuplicatePassedEvents() { PropertyBag properties = new(PassedTestNodeStateProperty.CachedInstance); @@ -125,13 +130,14 @@ public void PopulateTestNodeStatistics_WithDuplicatePassedEvents() _service.PopulateTestNodeStatistics(testNode); TestNodeStatistics statistics = _service.GetTestNodeStatistics(); - Assert.AreEqual(statistics.TotalDiscoveredTests, 0); - Assert.AreEqual(statistics.TotalPassedTests, 1); - Assert.AreEqual(statistics.TotalFailedTests, 0); - Assert.AreEqual(statistics.TotalPassedRetries, 1); - Assert.AreEqual(statistics.TotalFailedRetries, 0); + Assert.AreEqual(0, statistics.TotalDiscoveredTests); + Assert.AreEqual(1, statistics.TotalPassedTests); + Assert.AreEqual(0, statistics.TotalFailedTests); + Assert.AreEqual(1, statistics.TotalPassedRetries); + Assert.AreEqual(0, statistics.TotalFailedRetries); } + [TestMethod] public void PopulateTestNodeStatistics_WithEventsForSameUid() { PropertyBag properties = new( @@ -148,13 +154,14 @@ public void PopulateTestNodeStatistics_WithEventsForSameUid() _service.PopulateTestNodeStatistics(otherTestNode); TestNodeStatistics statistics = _service.GetTestNodeStatistics(); - Assert.AreEqual(statistics.TotalDiscoveredTests, 0); - Assert.AreEqual(statistics.TotalPassedTests, 1); - Assert.AreEqual(statistics.TotalFailedTests, 0); - Assert.AreEqual(statistics.TotalPassedRetries, 1); - Assert.AreEqual(statistics.TotalFailedRetries, 0); + Assert.AreEqual(0, statistics.TotalDiscoveredTests); + Assert.AreEqual(1, statistics.TotalPassedTests); + Assert.AreEqual(0, statistics.TotalFailedTests); + Assert.AreEqual(1, statistics.TotalPassedRetries); + Assert.AreEqual(0, statistics.TotalFailedRetries); } + [TestMethod] public void PopulateTestNodeStatistics_WithEventsForDifferentUids() { PropertyBag properties = new( @@ -171,14 +178,15 @@ public void PopulateTestNodeStatistics_WithEventsForDifferentUids() _service.PopulateTestNodeStatistics(otherTestNode); TestNodeStatistics statistics = _service.GetTestNodeStatistics(); - Assert.AreEqual(statistics.TotalDiscoveredTests, 0); - Assert.AreEqual(statistics.TotalPassedTests, 1); - Assert.AreEqual(statistics.TotalFailedTests, 1); - Assert.AreEqual(statistics.TotalPassedRetries, 0); - Assert.AreEqual(statistics.TotalFailedRetries, 0); + Assert.AreEqual(0, statistics.TotalDiscoveredTests); + Assert.AreEqual(1, statistics.TotalPassedTests); + Assert.AreEqual(1, statistics.TotalFailedTests); + Assert.AreEqual(0, statistics.TotalPassedRetries); + Assert.AreEqual(0, statistics.TotalFailedRetries); } - public async Task CleanupAsync(CleanupContext context) + [TestCleanup] + public async Task CleanupAsync() { if (_service.GetIdleUpdateTaskAsync() is { } idleUpdateTaskAsync) { @@ -186,7 +194,7 @@ public async Task CleanupAsync(CleanupContext context) } } - public void Dispose() => _service.Dispose(); + void IDisposable.Dispose() => _service.Dispose(); private sealed class DataProducer : IDataProducer { diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerTests.cs index ba16dad5dc..36f0db185d 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerTests.cs @@ -15,11 +15,10 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public class ServerTests : TestBase +[TestClass] +public sealed class ServerTests { - public ServerTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public ServerTests() { if (IsHotReloadEnabled(new SystemEnvironment())) { @@ -30,6 +29,7 @@ public ServerTests(ITestExecutionContext testExecutionContext) private static bool IsHotReloadEnabled(SystemEnvironment environment) => environment.GetEnvironmentVariable(EnvironmentVariableConstants.DOTNET_WATCH) == "1" || environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_HOTRELOAD_ENABLED) == "1"; + [TestMethod] public async Task ServerCanBeStartedAndAborted_TcpIp() => await RetryHelper.RetryAsync( async () => { @@ -51,6 +51,7 @@ public async Task ServerCanBeStartedAndAborted_TcpIp() => await RetryHelper.Retr Assert.AreEqual(ExitCodes.TestSessionAborted, await serverTask); }, 3, TimeSpan.FromSeconds(10)); + [TestMethod] public async Task ServerCanInitialize() { using var server = TcpServer.Create(); @@ -126,6 +127,7 @@ await WriteMessageAsync( Assert.AreEqual(0, result); } + [TestMethod] public async Task DiscoveryRequestCanBeCanceled() { using var server = TcpServer.Create(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/ServiceProviderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/ServiceProviderTests.cs index 2053169c0d..1ad71b8e80 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/ServiceProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/ServiceProviderTests.cs @@ -11,16 +11,12 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class ServiceProviderTests : TestBase +[TestClass] +public sealed class ServiceProviderTests { private readonly ServiceProvider _serviceProvider = new(); - public ServiceProviderTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public void GetService_InternalExtension_ShouldNotReturn() { _serviceProvider.AddService(new TestHostProcessLifetimeHandler()); @@ -39,6 +35,7 @@ public void GetService_InternalExtension_ShouldNotReturn() Assert.IsNull(_serviceProvider.GetService()); } + [TestMethod] public void GetServiceInternal_InternalExtension_ShouldReturn() { _serviceProvider.AddService(new TestHostProcessLifetimeHandler()); @@ -57,6 +54,7 @@ public void GetServiceInternal_InternalExtension_ShouldReturn() Assert.IsNotNull(_serviceProvider.GetServiceInternal()); } + [TestMethod] public void Clone_WithoutFilter_Succeeded() { _serviceProvider.AddService(new TestHostProcessLifetimeHandler()); @@ -74,6 +72,7 @@ public void Clone_WithoutFilter_Succeeded() } } + [TestMethod] public void Clone_WithFilter_Succeeded() { _serviceProvider.AddService(new TestHostProcessLifetimeHandler()); @@ -88,29 +87,37 @@ public void Clone_WithFilter_Succeeded() Assert.AreEqual(_serviceProvider.Services.ToArray()[0].GetType(), typeof(TestHostProcessLifetimeHandler)); } - public void AddService_TestFramework_ShouldFail() => _ = Assert.Throws(() => _serviceProvider.AddService(new TestFramework())); + [TestMethod] + public void AddService_TestFramework_ShouldFail() + => Assert.ThrowsException(() => _serviceProvider.AddService(new TestFramework())); - public void TryAddService_TestFramework_ShouldFail() => _ = Assert.Throws(() => _serviceProvider.TryAddService(new TestFramework())); + [TestMethod] + public void TryAddService_TestFramework_ShouldFail() + => Assert.ThrowsException(() => _serviceProvider.TryAddService(new TestFramework())); + [TestMethod] public void AddService_TestFramework_ShouldNotFail() { _serviceProvider.AllowTestAdapterFrameworkRegistration = true; _serviceProvider.AddService(new TestFramework()); } + [TestMethod] public void TryAddService_TestFramework_ShouldNotFail() { _serviceProvider.AllowTestAdapterFrameworkRegistration = true; _serviceProvider.TryAddService(new TestFramework()); } + [TestMethod] public void AddService_SameInstance_ShouldFail() { TestHostProcessLifetimeHandler instance = new(); _serviceProvider.AddService(instance); - _ = Assert.Throws(() => _serviceProvider.AddService(instance)); + _ = Assert.ThrowsException(() => _serviceProvider.AddService(instance)); } + [TestMethod] public void AddService_SameInstance_ShouldNotFail() { TestHostProcessLifetimeHandler instance = new(); @@ -118,13 +125,15 @@ public void AddService_SameInstance_ShouldNotFail() _serviceProvider.AddService(instance, throwIfSameInstanceExit: false); } + [TestMethod] public void AddServices_SameInstance_ShouldFail() { TestHostProcessLifetimeHandler instance = new(); _serviceProvider.AddServices([instance]); - _ = Assert.Throws(() => _serviceProvider.AddServices([instance])); + _ = Assert.ThrowsException(() => _serviceProvider.AddServices([instance])); } + [TestMethod] public void AddServices_SameInstance_ShouldNotFail() { TestHostProcessLifetimeHandler instance = new(); @@ -132,6 +141,7 @@ public void AddServices_SameInstance_ShouldNotFail() _serviceProvider.AddServices([instance], throwIfSameInstanceExit: false); } + [TestMethod] public void TryAddService_SameInstance_ShouldReturnFalse() { TestHostProcessLifetimeHandler instance = new(); @@ -139,6 +149,7 @@ public void TryAddService_SameInstance_ShouldReturnFalse() Assert.IsFalse(_serviceProvider.TryAddService(instance)); } + [TestMethod] public void GetServicesInternal_ExtensionMethod_InternalExtension_ShouldReturn() { _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); @@ -147,6 +158,7 @@ public void GetServicesInternal_ExtensionMethod_InternalExtension_ShouldReturn() Assert.AreEqual(2, _serviceProvider.GetServicesInternal().Count()); } + [TestMethod] public void GetServicesInternal_InternalExtension_ShouldNotReturn() { _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); @@ -155,6 +167,7 @@ public void GetServicesInternal_InternalExtension_ShouldNotReturn() Assert.AreEqual(0, _serviceProvider.GetServicesInternal(typeof(ITestApplicationLifecycleCallbacks), stopAtFirst: false, skipInternalOnlyExtensions: true).Count()); } + [TestMethod] public void GetServicesInternal_InternalExtension_ShouldReturn() { _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); @@ -163,6 +176,7 @@ public void GetServicesInternal_InternalExtension_ShouldReturn() Assert.AreEqual(2, _serviceProvider.GetServicesInternal(typeof(ITestApplicationLifecycleCallbacks), stopAtFirst: false, skipInternalOnlyExtensions: false).Count()); } + [TestMethod] public void GetServicesInternal_InternalExtension_FirstOnly_ShouldReturnOne() { _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); @@ -171,6 +185,7 @@ public void GetServicesInternal_InternalExtension_FirstOnly_ShouldReturnOne() Assert.AreEqual(1, _serviceProvider.GetServicesInternal(typeof(ITestApplicationLifecycleCallbacks), stopAtFirst: true, skipInternalOnlyExtensions: false).Count()); } + [TestMethod] public void GetServiceInternal_InternalExtension_ShouldReturnOne() { _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); @@ -179,7 +194,8 @@ public void GetServiceInternal_InternalExtension_ShouldReturnOne() Assert.IsNotNull(_serviceProvider.GetServiceInternal(typeof(ITestApplicationLifecycleCallbacks), skipInternalOnlyExtensions: false)); } - public void GetServiceInternal_InternalExtension_SkipInternalOnlyExtensios_ShouldReturnNull() + [TestMethod] + public void GetServiceInternal_InternalExtension_SkipInternalOnlyExtensions_ShouldReturnNull() { _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); _serviceProvider.AddService(new TestApplicationLifecycleCallbacks()); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/TestApplicationResultTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/TestApplicationResultTests.cs index 804d5aecf0..f16518ac06 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/TestApplicationResultTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Services/TestApplicationResultTests.cs @@ -11,24 +11,20 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class TestApplicationResultTests : TestBase +[TestClass] +public sealed class TestApplicationResultTests { private readonly TestApplicationResult _testApplicationResult = new(new Mock().Object, new Mock().Object, new Mock().Object, new Mock().Object); - public TestApplicationResultTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - + [TestMethod] public async Task GetProcessExitCodeAsync_If_All_Skipped_Returns_ZeroTestsRan() { await _testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(SkippedTestNodeStateProperty.CachedInstance), }), CancellationToken.None); @@ -36,13 +32,14 @@ public async Task GetProcessExitCodeAsync_If_All_Skipped_Returns_ZeroTestsRan() Assert.AreEqual(ExitCodes.ZeroTests, _testApplicationResult.GetProcessExitCode()); } + [TestMethod] public async Task GetProcessExitCodeAsync_If_No_Tests_Ran_Returns_ZeroTestsRan() { await _testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(), }), CancellationToken.None); @@ -50,14 +47,15 @@ public async Task GetProcessExitCodeAsync_If_No_Tests_Ran_Returns_ZeroTestsRan() Assert.AreEqual(ExitCodes.ZeroTests, _testApplicationResult.GetProcessExitCode()); } - [ArgumentsProvider(nameof(FailedState))] + [TestMethod] + [DynamicData(nameof(FailedState), DynamicDataSourceType.Method)] public async Task GetProcessExitCodeAsync_If_Failed_Tests_Returns_AtLeastOneTestFailed(TestNodeStateProperty testNodeStateProperty) { await _testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(testNodeStateProperty), }), CancellationToken.None); @@ -65,6 +63,7 @@ public async Task GetProcessExitCodeAsync_If_Failed_Tests_Returns_AtLeastOneTest Assert.AreEqual(ExitCodes.AtLeastOneTestFailed, _testApplicationResult.GetProcessExitCode()); } + [TestMethod] public async Task GetProcessExitCodeAsync_If_Canceled_Returns_TestSessionAborted() { Mock testApplicationCancellationTokenSource = new(); @@ -82,9 +81,9 @@ TestApplicationResult testApplicationResult await testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(), }), CancellationToken.None); @@ -92,14 +91,15 @@ TestApplicationResult testApplicationResult Assert.AreEqual(ExitCodes.TestSessionAborted, testApplicationResult.GetProcessExitCode()); } + [TestMethod] public async Task GetProcessExitCodeAsync_If_TestAdapter_Returns_TestAdapterTestSessionFailure() { await _testApplicationResult.SetTestAdapterTestSessionFailureAsync("Adapter error"); await _testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(PassedTestNodeStateProperty.CachedInstance), }), CancellationToken.None); @@ -107,6 +107,7 @@ public async Task GetProcessExitCodeAsync_If_TestAdapter_Returns_TestAdapterTest Assert.AreEqual(ExitCodes.TestAdapterTestSessionFailure, _testApplicationResult.GetProcessExitCode()); } + [TestMethod] public async Task GetProcessExitCodeAsync_If_MinimumExpectedTests_Violated_Returns_MinimumExpectedTestsPolicyViolation() { TestApplicationResult testApplicationResult @@ -117,18 +118,18 @@ TestApplicationResult testApplicationResult await testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(PassedTestNodeStateProperty.CachedInstance), }), CancellationToken.None); await testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(InProgressTestNodeStateProperty.CachedInstance), }), CancellationToken.None); @@ -136,6 +137,7 @@ TestApplicationResult testApplicationResult Assert.AreEqual(ExitCodes.MinimumExpectedTestsPolicyViolation, testApplicationResult.GetProcessExitCode()); } + [TestMethod] public async Task GetProcessExitCodeAsync_OnDiscovery_No_Tests_Discovered_Returns_ZeroTests() { TestApplicationResult testApplicationResult @@ -146,15 +148,16 @@ TestApplicationResult testApplicationResult await testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", }), CancellationToken.None); Assert.AreEqual(ExitCodes.ZeroTests, testApplicationResult.GetProcessExitCode()); } + [TestMethod] public async Task GetProcessExitCodeAsync_OnDiscovery_Some_Tests_Discovered_Returns_Success() { TestApplicationResult testApplicationResult @@ -165,9 +168,9 @@ TestApplicationResult testApplicationResult await testApplicationResult.ConsumeAsync(new DummyProducer(), new TestNodeUpdateMessage( default, - new Extensions.Messages.TestNode + new TestNode { - Uid = new Extensions.Messages.TestNodeUid("id"), + Uid = new TestNodeUid("id"), DisplayName = "DisplayName", Properties = new PropertyBag(DiscoveredTestNodeStateProperty.CachedInstance), }), CancellationToken.None); @@ -175,17 +178,18 @@ TestApplicationResult testApplicationResult Assert.AreEqual(ExitCodes.Success, testApplicationResult.GetProcessExitCode()); } - [Arguments("8", ExitCodes.Success)] - [Arguments("8;2", ExitCodes.Success)] - [Arguments("8;", ExitCodes.Success)] - [Arguments("8;2;", ExitCodes.Success)] - [Arguments("5", ExitCodes.ZeroTests)] - [Arguments("5;7", ExitCodes.ZeroTests)] - [Arguments("5;", ExitCodes.ZeroTests)] - [Arguments("5;7;", ExitCodes.ZeroTests)] - [Arguments(";", ExitCodes.ZeroTests)] - [Arguments(null, ExitCodes.ZeroTests)] - [Arguments("", ExitCodes.ZeroTests)] + [DataRow("8", ExitCodes.Success)] + [DataRow("8;2", ExitCodes.Success)] + [DataRow("8;", ExitCodes.Success)] + [DataRow("8;2;", ExitCodes.Success)] + [DataRow("5", ExitCodes.ZeroTests)] + [DataRow("5;7", ExitCodes.ZeroTests)] + [DataRow("5;", ExitCodes.ZeroTests)] + [DataRow("5;7;", ExitCodes.ZeroTests)] + [DataRow(";", ExitCodes.ZeroTests)] + [DataRow(null, ExitCodes.ZeroTests)] + [DataRow("", ExitCodes.ZeroTests)] + [TestMethod] public void GetProcessExitCodeAsync_IgnoreExitCodes(string argument, int expectedExitCode) { Mock environment = new(); @@ -208,12 +212,12 @@ public void GetProcessExitCodeAsync_IgnoreExitCodes(string argument, int expecte } } - internal static IEnumerable FailedState() + internal static IEnumerable FailedState() { - yield return new FailedTestNodeStateProperty(); - yield return new ErrorTestNodeStateProperty(); - yield return new CancelledTestNodeStateProperty(); - yield return new TimeoutTestNodeStateProperty(); + yield return new[] { new FailedTestNodeStateProperty() }; + yield return new[] { new ErrorTestNodeStateProperty() }; + yield return new[] { new CancelledTestNodeStateProperty() }; + yield return new[] { new TimeoutTestNodeStateProperty() }; } private sealed class CommandLineOption : ICommandLineOptions diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/ServerTelemetryTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/ServerTelemetryTests.cs index dfee39ce9f..8b754df5a8 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/ServerTelemetryTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/ServerTelemetryTests.cs @@ -9,15 +9,16 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class ServerTelemetryTests : TestBase +[TestClass] +public sealed class ServerTelemetryTests { private readonly ServerTelemetry _serverTelemetry; private readonly Mock _serverTestHost = new(); - public ServerTelemetryTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) => _serverTelemetry = new(_serverTestHost.Object); + public ServerTelemetryTests() + => _serverTelemetry = new(_serverTestHost.Object); + [TestMethod] public async Task LogEvent_ForDiscovery() { Dictionary metadata = new() @@ -30,6 +31,7 @@ public async Task LogEvent_ForDiscovery() _serverTestHost.Verify(s => s.SendTelemetryEventUpdateAsync(new TelemetryEventArgs(TelemetryEvents.TestsDiscoveryEventName, metadata))); } + [TestMethod] public async Task LogEvent_ForRun() { Dictionary metadata = new() diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/TelemetryManagerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/TelemetryManagerTests.cs index d66cd424f7..475b900da2 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/TelemetryManagerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Telemetry/TelemetryManagerTests.cs @@ -13,23 +13,19 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class TelemetryManagerTests : TestBase +[TestClass] +public sealed class TelemetryManagerTests { - public TelemetryManagerTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) - { - } - // When set to 1 or true it should suppress the message. - [Arguments(EnvironmentVariableConstants.TESTINGPLATFORM_NOBANNER, "1")] - [Arguments(EnvironmentVariableConstants.TESTINGPLATFORM_NOBANNER, "true")] - [Arguments(EnvironmentVariableConstants.DOTNET_NOLOGO, "1")] - [Arguments(EnvironmentVariableConstants.DOTNET_NOLOGO, "true")] + [DataRow(EnvironmentVariableConstants.TESTINGPLATFORM_NOBANNER, "1")] + [DataRow(EnvironmentVariableConstants.TESTINGPLATFORM_NOBANNER, "true")] + [DataRow(EnvironmentVariableConstants.DOTNET_NOLOGO, "1")] + [DataRow(EnvironmentVariableConstants.DOTNET_NOLOGO, "true")] // When set to 0 it should write the message. - [Arguments(EnvironmentVariableConstants.TESTINGPLATFORM_NOBANNER, "0")] - [Arguments(EnvironmentVariableConstants.DOTNET_NOLOGO, "0")] + [DataRow(EnvironmentVariableConstants.TESTINGPLATFORM_NOBANNER, "0")] + [DataRow(EnvironmentVariableConstants.DOTNET_NOLOGO, "0")] + [TestMethod] public async Task TelemetryManager_UsingNoLogoShouldSuppressTelemetryMessage(string variable, string value) { // Arrange @@ -75,14 +71,15 @@ public async Task TelemetryManager_UsingNoLogoShouldSuppressTelemetryMessage(str } // When set to 1 or true it should suppress the message. - [Arguments(EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "1")] - [Arguments(EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "true")] - [Arguments(EnvironmentVariableConstants.DOTNET_CLI_TELEMETRY_OPTOUT, "1")] - [Arguments(EnvironmentVariableConstants.DOTNET_CLI_TELEMETRY_OPTOUT, "true")] + [DataRow(EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "1")] + [DataRow(EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "true")] + [DataRow(EnvironmentVariableConstants.DOTNET_CLI_TELEMETRY_OPTOUT, "1")] + [DataRow(EnvironmentVariableConstants.DOTNET_CLI_TELEMETRY_OPTOUT, "true")] // When set to 0 it should write the message. - [Arguments(EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "0")] - [Arguments(EnvironmentVariableConstants.DOTNET_CLI_TELEMETRY_OPTOUT, "0")] + [DataRow(EnvironmentVariableConstants.TESTINGPLATFORM_TELEMETRY_OPTOUT, "0")] + [DataRow(EnvironmentVariableConstants.DOTNET_CLI_TELEMETRY_OPTOUT, "0")] + [TestMethod] public async Task TelemetryManager_UsingTelemetryOptOutShouldDisableTelemetry(string variable, string value) { // Arrange @@ -131,6 +128,7 @@ public async Task TelemetryManager_UsingTelemetryOptOutShouldDisableTelemetry(st } } + [TestMethod] public async Task TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNoticeOnSubsequentRuns() { // Arrange @@ -193,6 +191,7 @@ public async Task TelemetryManager_SentinelIsWrittenPerUserAndAvoidsShowingNotic fileSystemMock.Verify(f => f.NewFileStream(path, It.IsAny(), It.IsAny()), Times.Never); } + [TestMethod] public async Task TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessage() { // Arrange @@ -262,6 +261,7 @@ public async Task TelemetryManager_SentinelIsWrittenOnlyWhenUserWouldSeeTheMessa fileSystemMock.Verify(f => f.NewFileStream(path, It.IsAny(), It.IsAny()), Times.Once); } + [TestMethod] public async Task TelemetryManager_UsingNoBannerCommandLine_ShouldSuppressTelemetryMessage() { TestApplicationOptions options = new(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/TestApplicationBuilderTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/TestApplicationBuilderTests.cs index 0d58477da0..547f65e403 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/TestApplicationBuilderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/TestApplicationBuilderTests.cs @@ -14,13 +14,12 @@ namespace Microsoft.Testing.Platform.UnitTests; -[TestGroup] -public sealed class TestApplicationBuilderTests : TestBase +[TestClass] +public sealed class TestApplicationBuilderTests { private readonly ServiceProvider _serviceProvider = new(); - public TestApplicationBuilderTests(ITestExecutionContext testExecutionContext) - : base(testExecutionContext) + public TestApplicationBuilderTests() { CurrentTestApplicationModuleInfo testApplicationModuleInfo = new(new SystemEnvironment(), new SystemProcessHandler()); AggregatedConfiguration configuration = new([], testApplicationModuleInfo, new SystemFileSystem()); @@ -29,55 +28,61 @@ public TestApplicationBuilderTests(ITestExecutionContext testExecutionContext) _serviceProvider.AddService(configuration); } + [TestMethod] public async Task TestApplicationLifecycleCallbacks_DuplicatedId_ShouldFail() { TestHostManager testHostManager = new(); testHostManager.AddTestApplicationLifecycleCallbacks(_ => new ApplicationLifecycleCallbacks("duplicatedId")); testHostManager.AddTestApplicationLifecycleCallbacks(_ => new ApplicationLifecycleCallbacks("duplicatedId")); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostManager.BuildTestApplicationLifecycleCallbackAsync(_serviceProvider)); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostManager.BuildTestApplicationLifecycleCallbackAsync(_serviceProvider)); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(ApplicationLifecycleCallbacks).ToString())); } + [TestMethod] public async Task DataConsumer_DuplicatedId_ShouldFail() { TestHostManager testHostManager = new(); testHostManager.AddDataConsumer(_ => new Consumer("duplicatedId")); testHostManager.AddDataConsumer(_ => new Consumer("duplicatedId")); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostManager.BuildDataConsumersAsync(_serviceProvider, [])); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostManager.BuildDataConsumersAsync(_serviceProvider, [])); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(Consumer).ToString())); } + [TestMethod] public async Task DataConsumer_DuplicatedIdWithCompositeFactory_ShouldFail() { TestHostManager testHostManager = new(); CompositeExtensionFactory compositeExtensionFactory = new(() => new Consumer("duplicatedId")); testHostManager.AddDataConsumer(_ => new Consumer("duplicatedId")); testHostManager.AddDataConsumer(compositeExtensionFactory); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostManager.BuildDataConsumersAsync(_serviceProvider, [])); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostManager.BuildDataConsumersAsync(_serviceProvider, [])); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(Consumer).ToString())); } + [TestMethod] public async Task TestSessionLifetimeHandle_DuplicatedId_ShouldFail() { TestHostManager testHostManager = new(); testHostManager.AddTestSessionLifetimeHandle(_ => new TestSessionLifetimeHandler("duplicatedId")); testHostManager.AddTestSessionLifetimeHandle(_ => new TestSessionLifetimeHandler("duplicatedId")); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostManager.BuildTestSessionLifetimeHandleAsync(_serviceProvider, [])); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostManager.BuildTestSessionLifetimeHandleAsync(_serviceProvider, [])); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(TestSessionLifetimeHandler).ToString())); } + [TestMethod] public async Task TestSessionLifetimeHandle_DuplicatedIdWithCompositeFactory_ShouldFail() { TestHostManager testHostManager = new(); CompositeExtensionFactory compositeExtensionFactory = new(() => new TestSessionLifetimeHandler("duplicatedId")); testHostManager.AddTestSessionLifetimeHandle(_ => new TestSessionLifetimeHandler("duplicatedId")); testHostManager.AddTestSessionLifetimeHandle(compositeExtensionFactory); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostManager.BuildTestSessionLifetimeHandleAsync(_serviceProvider, [])); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostManager.BuildTestSessionLifetimeHandleAsync(_serviceProvider, [])); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(TestSessionLifetimeHandler).ToString())); } - [Arguments(true)] - [Arguments(false)] + [DataRow(true)] + [DataRow(false)] + [TestMethod] public async Task TestHost_ComposeFactory_ShouldSucceed(bool withParameter) { TestHostManager testHostManager = new(); @@ -96,46 +101,51 @@ public async Task TestHost_ComposeFactory_ShouldSucceed(bool withParameter) Assert.AreEqual(compositeExtensions[0].GetInstance(), sessionLifetimeHandle[0]); } + [TestMethod] public async Task TestHostControllerEnvironmentVariableProvider_DuplicatedId_ShouldFail() { TestHostControllersManager testHostControllerManager = new(); testHostControllerManager.AddEnvironmentVariableProvider(_ => new TestHostEnvironmentVariableProvider("duplicatedId")); testHostControllerManager.AddEnvironmentVariableProvider(_ => new TestHostEnvironmentVariableProvider("duplicatedId")); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(TestHostEnvironmentVariableProvider).ToString())); } + [TestMethod] public async Task TestHostControllerEnvironmentVariableProvider_DuplicatedIdWithCompositeFactory_ShouldFail() { TestHostControllersManager testHostControllerManager = new(); CompositeExtensionFactory compositeExtensionFactory = new(() => new TestHostEnvironmentVariableProvider("duplicatedId")); testHostControllerManager.AddEnvironmentVariableProvider(_ => new TestHostEnvironmentVariableProvider("duplicatedId")); testHostControllerManager.AddEnvironmentVariableProvider(compositeExtensionFactory); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(TestHostEnvironmentVariableProvider).ToString())); } + [TestMethod] public async Task TestHostControllerProcessLifetimeHandler_DuplicatedId_ShouldFail() { TestHostControllersManager testHostControllerManager = new(); testHostControllerManager.AddProcessLifetimeHandler(_ => new TestHostProcessLifetimeHandler("duplicatedId")); testHostControllerManager.AddProcessLifetimeHandler(_ => new TestHostProcessLifetimeHandler("duplicatedId")); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(TestHostProcessLifetimeHandler).ToString())); } + [TestMethod] public async Task TestHostControllerProcessLifetimeHandler_DuplicatedIdWithCompositeFactory_ShouldFail() { TestHostControllersManager testHostControllerManager = new(); CompositeExtensionFactory compositeExtensionFactory = new(() => new TestHostProcessLifetimeHandler("duplicatedId")); testHostControllerManager.AddProcessLifetimeHandler(_ => new TestHostProcessLifetimeHandler("duplicatedId")); testHostControllerManager.AddProcessLifetimeHandler(compositeExtensionFactory); - InvalidOperationException invalidOperationException = await Assert.ThrowsAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); + InvalidOperationException invalidOperationException = await Assert.ThrowsExceptionAsync(() => testHostControllerManager.BuildAsync(_serviceProvider)); Assert.IsTrue(invalidOperationException.Message.Contains("duplicatedId") && invalidOperationException.Message.Contains(typeof(TestHostProcessLifetimeHandler).ToString())); } - [Arguments(true)] - [Arguments(false)] + [DataRow(true)] + [DataRow(false)] + [TestMethod] public async Task TestHostController_ComposeFactory_ShouldSucceed(bool withParameter) { TestHostControllersManager testHostControllerManager = new(); @@ -154,15 +164,16 @@ public async Task TestHostController_ComposeFactory_ShouldSucceed(bool withParam Assert.AreEqual(((ICompositeExtensionFactory)compositeExtensionFactory).GetInstance(), configuration.EnvironmentVariableProviders[0]); } - [Arguments(true)] - [Arguments(false)] + [DataRow(true)] + [DataRow(false)] + [TestMethod] public void ComposeFactory_InvalidComposition_ShouldFail(bool withParameter) { CompositeExtensionFactory compositeExtensionFactory = withParameter ? new CompositeExtensionFactory(sp => new InvalidComposition(sp)) : new CompositeExtensionFactory(() => new InvalidComposition()); - InvalidOperationException invalidOperationException = Assert.Throws(() => ((ICompositeExtensionFactory)compositeExtensionFactory).GetInstance()); + InvalidOperationException invalidOperationException = Assert.ThrowsException(() => ((ICompositeExtensionFactory)compositeExtensionFactory).GetInstance()); Assert.AreEqual(CompositeExtensionFactory.ValidateCompositionErrorMessage, invalidOperationException.Message); } diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/Constants.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/Constants.cs index a4489f8b11..65c5414243 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/Constants.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/Constants.cs @@ -3,6 +3,9 @@ using System.Runtime.InteropServices; +// TODO: this should not be required +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] + namespace Microsoft.Testing.TestInfrastructure; public static class Constants diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj b/test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj index 927d31caaf..ebff01df15 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj @@ -1,4 +1,4 @@ - + $(MicrosoftTestingTargetFrameworks);netstandard2.0 @@ -7,18 +7,18 @@ - + + - - - + + diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/RetryHelper.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/RetryHelper.cs index c0261fca89..a2adaf6262 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/RetryHelper.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/RetryHelper.cs @@ -7,11 +7,13 @@ namespace Microsoft.Testing.TestInfrastructure; public class RetryHelper { - public static async Task RetryAsync(Func action, uint times, TimeSpan every, Func? predicate = null) => await Policy.Handle(exception => predicate is null || predicate(exception)) + public static async Task RetryAsync(Func action, uint times, TimeSpan every, Func? predicate = null) + => await Policy.Handle(exception => predicate is null || predicate(exception)) .WaitAndRetryAsync((int)times, _ => every) .ExecuteAsync(action); - public static async Task RetryAsync(Func> action, uint times, TimeSpan every, Func? predicate = null) => await Policy.Handle(exception => predicate is null || predicate(exception)) + public static async Task RetryAsync(Func> action, uint times, TimeSpan every, Func? predicate = null) + => await Policy.Handle(exception => predicate is null || predicate(exception)) .WaitAndRetryAsync((int)times, _ => every) .ExecuteAsync(action); } diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/SourceCodeExtensions.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/SourceCodeExtensions.cs index 88e502c555..afa810c240 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/SourceCodeExtensions.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/SourceCodeExtensions.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Testing.Internal.Framework; - namespace Microsoft.Testing.TestInfrastructure; public static class SourceCodeExtensions @@ -10,6 +8,6 @@ public static class SourceCodeExtensions public static string PatchCodeWithReplace(this string code, string pattern, string value) => code.Replace(pattern, value); - public static string PatchTargetFrameworks(this string code, params TestArgumentsEntry[] targetFrameworks) + public static string PatchTargetFrameworks(this string code, params string[] targetFrameworks) => PatchCodeWithReplace(code, "$TargetFrameworks$", targetFrameworks.ToMSBuildTargetFrameworks()); } diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/TargetFrameworks.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/TargetFrameworks.cs index f5bdc6d05e..58ec8a7d21 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/TargetFrameworks.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/TargetFrameworks.cs @@ -3,31 +3,35 @@ using System.Runtime.InteropServices; -using Microsoft.Testing.Internal.Framework; - namespace Microsoft.Testing.TestInfrastructure; public static class TargetFrameworks { - public static TestArgumentsEntry[] Net { get; } = + public static string[] Net { get; } = [ - new("net9.0", "net9.0"), + "net9.0", #if !SKIP_INTERMEDIATE_TARGET_FRAMEWORKS - new("net8.0", "net8.0"), - new("net7.0", "net7.0"), - new("net6.0", "net6.0"), + "net8.0", + "net7.0", + "net6.0", #endif ]; - public static TestArgumentsEntry NetCurrent { get; } = Net[0]; + public static IEnumerable NetForDynamicData { get; } = + Net.Select(tfm => new object[] { tfm }); + + public static string NetCurrent { get; } = Net[0]; - public static TestArgumentsEntry[] NetFramework { get; } = [new("net462", "net462")]; + public static string[] NetFramework { get; } = ["net462"]; - public static TestArgumentsEntry[] All { get; } + public static string[] All { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Net.Concat(NetFramework).ToArray() : Net; - public static string ToMSBuildTargetFrameworks(this TestArgumentsEntry[] targetFrameworksEntries) - => string.Join(";", targetFrameworksEntries.Select(x => x.Arguments)); + public static IEnumerable AllForDynamicData { get; } = + All.Select(tfm => new object[] { tfm }); + + public static string ToMSBuildTargetFrameworks(this string[] targetFrameworksEntries) + => string.Join(";", targetFrameworksEntries); } diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs index e40adefc3e..0f25e2993b 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/TestAssetFixtureBase.cs @@ -3,24 +3,37 @@ using System.Collections.Concurrent; -using Microsoft.Testing.Internal.Framework; - namespace Microsoft.Testing.TestInfrastructure; -public abstract class TestAssetFixtureBase : IDisposable, IAsyncInitializable +public interface ITestAssetFixture : IDisposable +{ + Task InitializeAsync(); +} + +public sealed class NopAssetFixture : ITestAssetFixture +{ + public Task InitializeAsync() => Task.CompletedTask; + + public void Dispose() + { + } +} + +public abstract class TestAssetFixtureBase : ITestAssetFixture { private readonly ConcurrentDictionary _testAssets = new(); private readonly TempDirectory _nugetGlobalPackagesDirectory; private bool _disposedValue; - protected TestAssetFixtureBase(TempDirectory nugetGlobalPackagesDirectory) => _nugetGlobalPackagesDirectory = nugetGlobalPackagesDirectory; + protected TestAssetFixtureBase(TempDirectory nugetGlobalPackagesDirectory) + => _nugetGlobalPackagesDirectory = nugetGlobalPackagesDirectory; public string GetAssetPath(string assetID) => !_testAssets.TryGetValue(assetID, out TestAsset? testAsset) ? throw new ArgumentNullException(nameof(assetID), $"Cannot find target path for test asset '{assetID}'") : testAsset.TargetAssetPath; - public async Task InitializeAsync(InitializationContext context) + public async Task InitializeAsync() #if NET => await Parallel.ForEachAsync(GetAssetsToGenerate(), async (asset, _) => { diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestBase.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/TestBase.cs deleted file mode 100644 index c5124a15f3..0000000000 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestBase.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.Testing.Internal.Framework; - -namespace Microsoft.Testing.TestInfrastructure; - -public abstract class TestBase -{ - protected TestBase(ITestExecutionContext testExecutionContext) => TestsRunWatchDog.AddTestRun(testExecutionContext.TestInfo.StableUid); -} diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestsRunWatchDog.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/TestsRunWatchDog.cs deleted file mode 100644 index f35320d659..0000000000 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/TestsRunWatchDog.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Concurrent; -using System.Globalization; -using System.Text; - -using Microsoft.Testing.Internal.Framework; - -namespace Microsoft.Testing.TestInfrastructure; - -public static class TestsRunWatchDog -{ - private static readonly ConcurrentDictionary TestNodes = new(); - - public static string? BaselineFile { get; set; } - - public static void AddTestRun(TestNodeUid testNodeUid) => TestNodes.AddOrUpdate(testNodeUid, 1, (_, count) => count + 1); - - public static async Task VerifyAsync(bool skip = false, bool fixBaseLine = false) - { - if (skip) - { - return; - } - - if (BaselineFile is null) - { - throw new InvalidOperationException("Baseline file should not be null"); - } - - if (TestNodes.IsEmpty) - { - throw new InvalidOperationException("No tests were executed. Have you called 'TestsRunWatchDog.AddTestRun'?"); - } - - List expectedTestsDidNotRun = []; - List unexpectedRanTests = []; - using (FileStream fs = File.OpenRead(BaselineFile)) - { - using StreamReader streamReader = new(fs); - string? testFullyQualifiedName; - while ((testFullyQualifiedName = await streamReader.ReadLineAsync()) != null) - { - if (string.IsNullOrWhiteSpace(testFullyQualifiedName)) - { - // Skip empty lines. - continue; - } - else if (!TestNodes.TryGetValue(testFullyQualifiedName, out int _)) - { - expectedTestsDidNotRun.Add(testFullyQualifiedName); - } - else - { - TestNodes[testFullyQualifiedName]--; - if (TestNodes[testFullyQualifiedName] == 0) - { - TestNodes.TryRemove(testFullyQualifiedName, out _); - } - } - } - } - - if (!TestNodes.IsEmpty) - { - foreach (KeyValuePair notRunNodes in TestNodes) - { - for (int i = 0; i < notRunNodes.Value; i++) - { - unexpectedRanTests.Add(notRunNodes.Key.Value); - } - } - } - - StringBuilder sb = new(); - if (unexpectedRanTests.Count > 0) - { - sb.AppendLine(); - sb.AppendLine(CultureInfo.InvariantCulture, $"Unexpected tests that ran (base line file name {BaselineFile}):"); - sb.AppendLine(); - foreach (string unexpectedTest in unexpectedRanTests) - { - sb.AppendLine(unexpectedTest); - } - } - - if (expectedTestsDidNotRun.Count > 0) - { - sb.AppendLine(); - sb.AppendLine(CultureInfo.InvariantCulture, $"Expected tests that did not run (base line file name {BaselineFile}):"); - sb.AppendLine(); - foreach (string missingTest in expectedTestsDidNotRun) - { - sb.AppendLine(missingTest); - } - } - - try - { - if (unexpectedRanTests.Count > 0 || expectedTestsDidNotRun.Count > 0) - { - throw new InvalidOperationException(sb.ToString()); - } - } - finally - { - if (fixBaseLine) - { - List tests = [.. File.ReadAllLines(BaselineFile)]; - tests.RemoveAll(expectedTestsDidNotRun.Contains); - tests.AddRange(unexpectedRanTests); - tests.Sort(); - File.WriteAllLines(BaselineFile, tests); - Console.WriteLine(); - Console.WriteLine($"FIXED BASELINE: '{BaselineFile}'"); - } - } - } -}