Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AsyncTestProperty #4725

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ internal static class Constants

internal static readonly TestProperty DeclaringClassNameProperty = TestProperty.Register("MSTestDiscoverer.DeclaringClassName", DeclaringClassNameLabel, typeof(string), TestPropertyAttributes.Hidden, typeof(TestCase));

internal static readonly TestProperty AsyncTestProperty = TestProperty.Register("MSTestDiscoverer.IsAsync", IsAsyncLabel, typeof(bool), TestPropertyAttributes.Hidden, typeof(TestCase));

#pragma warning disable CS0618 // Type or member is obsolete
internal static readonly TestProperty TestCategoryProperty = TestProperty.Register("MSTestDiscoverer.TestCategory", TestCategoryLabel, typeof(string[]), TestPropertyAttributes.Hidden | TestPropertyAttributes.Trait, typeof(TestCase));
#pragma warning restore CS0618 // Type or member is obsolete
Expand Down Expand Up @@ -136,7 +134,6 @@ internal static class Constants
/// </summary>
private const string TestClassNameLabel = "ClassName";
private const string DeclaringClassNameLabel = "DeclaringClassName";
private const string IsAsyncLabel = "IsAsync";
private const string TestCategoryLabel = "TestCategory";
private const string PriorityLabel = "Priority";
private const string DeploymentItemsLabel = "DeploymentItems";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static string GetMethodName(MethodInfo methodInfo)

static UnitTestElement GetFixtureTest(string classFullName, string assemblyLocation, string fixtureType, string methodName, string[] hierarchy)
{
var method = new TestMethod(classFullName, methodName, hierarchy, methodName, classFullName, assemblyLocation, false, null, TestIdGenerationStrategy.FullyQualified);
var method = new TestMethod(classFullName, methodName, hierarchy, methodName, classFullName, assemblyLocation, null, TestIdGenerationStrategy.FullyQualified);
return new UnitTestElement(method)
{
DisplayName = $"[{fixtureType}] {methodName}",
Expand Down
5 changes: 1 addition & 4 deletions src/Adapter/MSTest.TestAdapter/Discovery/TypeEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,9 @@ internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInT
// null if the current instance represents a generic type parameter.
DebugEx.Assert(_type.AssemblyQualifiedName != null, "AssemblyQualifiedName for method is null.");

// This allows void returning async test method to be valid test method. Though they will be executed similar to non-async test method.
bool isAsync = ReflectHelper.MatchReturnType(method, typeof(Task));

ManagedNameHelper.GetManagedName(method, out string managedType, out string managedMethod, out string?[]? hierarchyValues);
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = null; // This one will be set by test windows to current test project name.
var testMethod = new TestMethod(managedType, managedMethod, hierarchyValues, method.Name, _type.FullName!, _assemblyFilePath, isAsync, null, _testIdGenerationStrategy);
var testMethod = new TestMethod(managedType, managedMethod, hierarchyValues, method.Name, _type.FullName!, _assemblyFilePath, null, _testIdGenerationStrategy);

if (!string.Equals(method.DeclaringType!.FullName, _type.FullName, StringComparison.Ordinal))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ internal static string GetTestName(this TestCase testCase, string? testClassName
/// <returns> The converted <see cref="UnitTestElement"/>. </returns>
internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string source)
{
bool isAsync = (testCase.GetPropertyValue(Constants.AsyncTestProperty) as bool?) ?? false;
string? testClassName = testCase.GetPropertyValue(Constants.TestClassNameProperty) as string;
string name = testCase.GetTestName(testClassName);
var testIdGenerationStrategy = (TestIdGenerationStrategy)testCase.GetPropertyValue(
Constants.TestIdGenerationStrategyProperty,
(int)TestIdGenerationStrategy.FullyQualified);

TestMethod testMethod = testCase.ContainsManagedMethodAndType()
? new(testCase.GetManagedType(), testCase.GetManagedMethod(), testCase.GetHierarchy()!, name, testClassName!, source, isAsync, testCase.DisplayName, testIdGenerationStrategy)
: new(name, testClassName!, source, isAsync, testCase.DisplayName, testIdGenerationStrategy);
? new(testCase.GetManagedType(), testCase.GetManagedMethod(), testCase.GetHierarchy()!, name, testClassName!, source, testCase.DisplayName, testIdGenerationStrategy)
: new(name, testClassName!, source, testCase.DisplayName, testIdGenerationStrategy);
var dataType = (DynamicDataType)testCase.GetPropertyValue(Constants.TestDynamicDataTypeProperty, (int)DynamicDataType.None);
if (dataType != DynamicDataType.None)
{
Expand All @@ -96,7 +95,6 @@ internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string

UnitTestElement testElement = new(testMethod)
{
IsAsync = isAsync,
TestCategory = testCase.GetPropertyValue(Constants.TestCategoryProperty) as string[],
Priority = testCase.GetPropertyValue(Constants.PriorityProperty) as int?,
DisplayName = testCase.DisplayName,
Expand Down
13 changes: 7 additions & 6 deletions src/Adapter/MSTest.TestAdapter/ObjectModel/TestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ public sealed class TestMethod : ITestMethod
private string? _declaringClassFullName;
private string? _declaringAssemblyName;

#pragma warning disable IDE0060 // Remove unused parameter - Public API :/
public TestMethod(string name, string fullClassName, string assemblyName, bool isAsync)
: this(null, null, null, name, fullClassName, assemblyName, isAsync, null, TestIdGenerationStrategy.FullyQualified)
#pragma warning restore IDE0060 // Remove unused parameter
: this(null, null, null, name, fullClassName, assemblyName, null, TestIdGenerationStrategy.FullyQualified)
{
}

internal TestMethod(string name, string fullClassName, string assemblyName, bool isAsync, string? displayName,
internal TestMethod(string name, string fullClassName, string assemblyName, string? displayName,
TestIdGenerationStrategy testIdGenerationStrategy)
: this(null, null, null, name, fullClassName, assemblyName, isAsync, displayName, testIdGenerationStrategy)
: this(null, null, null, name, fullClassName, assemblyName, displayName, testIdGenerationStrategy)
{
}

internal TestMethod(string? managedTypeName, string? managedMethodName, string?[]? hierarchyValues, string name,
string fullClassName, string assemblyName, bool isAsync, string? displayName,
string fullClassName, string assemblyName, string? displayName,
TestIdGenerationStrategy testIdGenerationStrategy)
{
Guard.NotNullOrWhiteSpace(assemblyName);
Expand All @@ -55,7 +57,6 @@ internal TestMethod(string? managedTypeName, string? managedMethodName, string?[
DisplayName = displayName ?? name;
FullClassName = fullClassName;
AssemblyName = assemblyName;
IsAsync = isAsync;

if (hierarchyValues is null)
{
Expand Down Expand Up @@ -115,7 +116,7 @@ public string? DeclaringClassFullName
public string AssemblyName { get; private set; }

/// <inheritdoc />
public bool IsAsync { get; private set; }
public bool IsAsync => false; // TODO: Remove this property. We can't remove now as it's public and breaking change.

/// <inheritdoc />
public string? ManagedTypeName { get; }
Expand Down
11 changes: 0 additions & 11 deletions src/Adapter/MSTest.TestAdapter/ObjectModel/UnitTestElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public UnitTestElement(TestMethod testMethod)
/// </summary>
public TestMethod TestMethod { get; private set; }

/// <summary>
/// Gets or sets a value indicating whether it is a async test.
/// </summary>
public bool IsAsync { get; set; }

/// <summary>
/// Gets or sets the test categories for test method.
/// </summary>
Expand Down Expand Up @@ -144,12 +139,6 @@ internal TestCase ToTestCase()
testCase.SetPropertyValue(Constants.DeclaringClassNameProperty, TestMethod.DeclaringClassFullName);
}

// Many of the tests will not be async, so there is no point in sending extra data
if (IsAsync)
{
testCase.SetPropertyValue(Constants.AsyncTestProperty, IsAsync);
}

// Set only if some test category is present
if (TestCategory is { Length: > 0 })
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@ public void ToUnitTestElementShouldReturnUnitTestElementWithFieldsSet()
};
string[] testCategories = ["DummyCategory"];

testCase.SetPropertyValue(Constants.AsyncTestProperty, true);
testCase.SetPropertyValue(Constants.PriorityProperty, 2);
testCase.SetPropertyValue(Constants.TestCategoryProperty, testCategories);
testCase.SetPropertyValue(Constants.TestClassNameProperty, "DummyClassName");

var resultUnitTestElement = testCase.ToUnitTestElement(testCase.Source);

Verify(resultUnitTestElement.IsAsync);
Verify(resultUnitTestElement.Priority == 2);
Verify(testCategories == resultUnitTestElement.TestCategory);
Verify(resultUnitTestElement.DisplayName == "DummyDisplayName");
Verify(resultUnitTestElement.TestMethod.Name == "DummyMethod");
Verify(resultUnitTestElement.TestMethod.FullClassName == "DummyClassName");
Verify(resultUnitTestElement.TestMethod.IsAsync);
Verify(resultUnitTestElement.TestMethod.DeclaringClassFullName is null);
}

Expand All @@ -45,7 +42,6 @@ public void ToUnitTestElementForTestCaseWithNoPropertiesShouldReturnUnitTestElem
var resultUnitTestElement = testCase.ToUnitTestElement(testCase.Source);

// These are set for testCase by default by ObjectModel.
Verify(!resultUnitTestElement.IsAsync);
Verify(resultUnitTestElement.Priority == 0);
Verify(resultUnitTestElement.TestCategory is null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ public void ToTestCaseShouldSetDeclaringClassNameIfPresent()
Verify((testCase.GetPropertyValue(Constants.DeclaringClassNameProperty) as string) == "DC");
}

public void ToTestCaseShouldSetIsAsyncProperty()
{
_unitTestElement.IsAsync = true;
var testCase = _unitTestElement.ToTestCase();

Verify((bool)testCase.GetPropertyValue(Constants.AsyncTestProperty));

_unitTestElement.IsAsync = false;
testCase = _unitTestElement.ToTestCase();

Verify(!(bool)testCase.GetPropertyValue(Constants.AsyncTestProperty));
}

public void ToTestCaseShouldSetTestCategoryIfPresent()
{
_unitTestElement.TestCategory = null;
Expand Down Expand Up @@ -188,7 +175,7 @@ public void ToTestCase_WhenStrategyIsLegacy_UsesDefaultTestCaseId()
#pragma warning disable CA2263 // Prefer generic overload when type is known
foreach (DynamicDataType dataType in Enum.GetValues(typeof(DynamicDataType)))
{
var testCase = new UnitTestElement(new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, TestIdGenerationStrategy.Legacy) { DataType = dataType }).ToTestCase();
var testCase = new UnitTestElement(new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, TestIdGenerationStrategy.Legacy) { DataType = dataType }).ToTestCase();
var expectedTestCase = new TestCase(testCase.FullyQualifiedName, testCase.ExecutorUri, testCase.Source);
Verify(expectedTestCase.Id == testCase.Id);
Verify(testCase.GetPropertyValue(Constants.TestIdGenerationStrategyProperty).Equals((int)TestIdGenerationStrategy.Legacy));
Expand All @@ -202,7 +189,7 @@ public void ToTestCase_WhenStrategyIsDisplayName_DoesNotUseDefaultTestCaseId()
#pragma warning disable CA2263 // Prefer generic overload when type is known
foreach (DynamicDataType dataType in Enum.GetValues(typeof(DynamicDataType)))
{
var testCase = new UnitTestElement(new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, TestIdGenerationStrategy.DisplayName) { DataType = dataType }).ToTestCase();
var testCase = new UnitTestElement(new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, TestIdGenerationStrategy.DisplayName) { DataType = dataType }).ToTestCase();
var expectedTestCase = new TestCase(testCase.FullyQualifiedName, testCase.ExecutorUri, testCase.Source);
if (dataType == DynamicDataType.None)
{
Expand All @@ -223,7 +210,7 @@ public void ToTestCase_WhenStrategyIsData_DoesNotUseDefaultTestCaseId()
#pragma warning disable CA2263 // Prefer generic overload when type is known
foreach (DynamicDataType dataType in Enum.GetValues(typeof(DynamicDataType)))
{
var testCase = new UnitTestElement(new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, TestIdGenerationStrategy.FullyQualified) { DataType = dataType }).ToTestCase();
var testCase = new UnitTestElement(new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, TestIdGenerationStrategy.FullyQualified) { DataType = dataType }).ToTestCase();
var expectedTestCase = new TestCase(testCase.FullyQualifiedName, testCase.ExecutorUri, testCase.Source);
Verify(expectedTestCase.Id != testCase.Id);
Verify(testCase.GetPropertyValue(Constants.TestIdGenerationStrategyProperty).Equals((int)TestIdGenerationStrategy.FullyQualified));
Expand All @@ -238,19 +225,19 @@ public void ToTestCase_WhenStrategyIsDisplayName_ExamplesOfTestCaseIdUniqueness(
TestCase[] testCases =
[
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy))
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyOtherMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy))
new("MyOtherMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyOtherProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy))
new("MyMethod", "MyOtherProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyOtherAssembly", false, null, testIdStrategy))
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyOtherAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.DataSourceAttribute,
})
Expand All @@ -259,7 +246,7 @@ public void ToTestCase_WhenStrategyIsDisplayName_ExamplesOfTestCaseIdUniqueness(
}
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.ITestDataSource,
})
Expand All @@ -279,34 +266,34 @@ public void ToTestCase_WhenStrategyIsDisplayName_ExamplesOfTestCaseIdCollision()
TestCase[] testCases =
[
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.DataSourceAttribute,
})
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.DataSourceAttribute,
SerializedData = ["1"],
})
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.DataSourceAttribute,
SerializedData = ["2"],
})
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.ITestDataSource,
SerializedData = ["1"],
})
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
DataType = DynamicDataType.ITestDataSource,
SerializedData = ["2"],
Expand All @@ -323,31 +310,31 @@ public void ToTestCase_WhenStrategyIsFullyQualifiedTest_ExamplesOfTestCaseIdUniq
TestCase[] testCases =
[
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy))
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyOtherMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy))
new("MyOtherMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyOtherProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy))
new("MyMethod", "MyOtherProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyOtherAssembly", false, null, testIdStrategy))
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyOtherAssembly", null, testIdStrategy))
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
SerializedData = ["System.Int32[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "[]"],
})
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
SerializedData = ["System.Int32[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "[1]"],
})
.ToTestCase(),
new UnitTestElement(
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", false, null, testIdStrategy)
new("MyMethod", "MyProduct.MyNamespace.MyClass", "MyAssembly", null, testIdStrategy)
{
SerializedData = ["System.Int32[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "[1,1]"],
})
Expand Down