Skip to content

Improve display name for string and char #3082

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

Merged
merged 20 commits into from
Jun 10, 2024
Merged
Changes from 16 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
Original file line number Diff line number Diff line change
@@ -95,15 +95,24 @@ public DataRowAttribute(params object?[]? data)
/// </summary>
private static string? GetObjectString(object? obj)
{
if (TestIdGenerationStrategy != TestIdGenerationStrategy.FullyQualified)
{
return obj?.ToString();
}

if (obj == null)
{
return null;
return "null";
}

if (TestIdGenerationStrategy != TestIdGenerationStrategy.FullyQualified
|| !obj.GetType().IsArray)
if (!obj.GetType().IsArray)
{
return obj.ToString();
return obj switch
{
string s => $"\"{s}\"",
char c => $"'{c}'",
_ => obj.ToString(),
};
}

// We need to box the object here so that we can support value types
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// // 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.MSTestV2.CLIAutomation;
@@ -21,11 +22,11 @@ public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRow
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethod (BaseString1)",
"DataRowTestMethod (BaseString2)",
"DataRowTestMethod (BaseString3)",
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
"DataRowTestMethod (\"BaseString1\")",
"DataRowTestMethod (\"BaseString2\")",
"DataRowTestMethod (\"BaseString3\")",
"DataRowTestMethod (\"DerivedString1\")",
"DataRowTestMethod (\"DerivedString2\")");
}

public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
@@ -40,8 +41,8 @@ public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_Simp
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
"DataRowTestMethod (\"DerivedString1\")",
"DataRowTestMethod (\"DerivedString2\")");
}

public void DataRowsExecuteWithRequiredAndOptionalParameters()
@@ -57,8 +58,8 @@ public void DataRowsExecuteWithRequiredAndOptionalParameters()
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodWithSomeOptionalParameters (123)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString1\")",
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString2\",\"DerivedOptionalString3\")");
}

public void DataRowsExecuteWithParamsArrayParameter()
@@ -74,9 +75,9 @@ public void DataRowsExecuteWithParamsArrayParameter()
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethodWithParamsParameters (2)",
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
"DataRowTestMethodWithParamsParameters (2,\"DerivedSingleParamsArg\")",
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\")",
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\",\"DerivedParamsArg3\")");
}

public void DataRowsFailWhenInvalidArgumentsProvided()
@@ -93,7 +94,7 @@ public void DataRowsFailWhenInvalidArgumentsProvided()
testResults,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
}

public void DataRowsShouldSerializeDoublesProperly()
@@ -124,7 +125,7 @@ public void DataRowsShouldSerializeMixedTypesProperly()
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMixed (10,10,10,10,10,10,10,10)");
"DataRowTestMixed (10,10,10,10,10,10,10,\"10\")");
}

public void DataRowsShouldSerializeEnumsProperly()
@@ -139,7 +140,7 @@ public void DataRowsShouldSerializeEnumsProperly()
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowEnums ()",
"DataRowEnums (null)",
"DataRowEnums (Alfa)",
"DataRowEnums (Beta)",
"DataRowEnums (Gamma)");
@@ -202,35 +203,35 @@ public void ExecuteDataRowTests_Enums()
"DataRowEnum_ULong (Alfa)",
"DataRowEnum_ULong (Beta)",
"DataRowEnum_ULong (Gamma)",
"DataRowEnums_Nullable_SByte ()",
"DataRowEnums_Nullable_SByte (null)",
"DataRowEnums_Nullable_SByte (Alfa)",
"DataRowEnums_Nullable_SByte (Beta)",
"DataRowEnums_Nullable_SByte (Gamma)",
"DataRowEnums_Nullable_Byte ()",
"DataRowEnums_Nullable_Byte (null)",
"DataRowEnums_Nullable_Byte (Alfa)",
"DataRowEnums_Nullable_Byte (Beta)",
"DataRowEnums_Nullable_Byte (Gamma)",
"DataRowEnums_Nullable_Short ()",
"DataRowEnums_Nullable_Short (null)",
"DataRowEnums_Nullable_Short (Alfa)",
"DataRowEnums_Nullable_Short (Beta)",
"DataRowEnums_Nullable_Short (Gamma)",
"DataRowEnums_Nullable_UShort ()",
"DataRowEnums_Nullable_UShort (null)",
"DataRowEnums_Nullable_UShort (Alfa)",
"DataRowEnums_Nullable_UShort (Beta)",
"DataRowEnums_Nullable_UShort (Gamma)",
"DataRowEnums_Nullable_Int ()",
"DataRowEnums_Nullable_Int (null)",
"DataRowEnums_Nullable_Int (Alfa)",
"DataRowEnums_Nullable_Int (Beta)",
"DataRowEnums_Nullable_Int (Gamma)",
"DataRowEnums_Nullable_UInt ()",
"DataRowEnums_Nullable_UInt (null)",
"DataRowEnums_Nullable_UInt (Alfa)",
"DataRowEnums_Nullable_UInt (Beta)",
"DataRowEnums_Nullable_UInt (Gamma)",
"DataRowEnums_Nullable_Long ()",
"DataRowEnums_Nullable_Long (null)",
"DataRowEnums_Nullable_Long (Alfa)",
"DataRowEnums_Nullable_Long (Beta)",
"DataRowEnums_Nullable_Long (Gamma)",
"DataRowEnums_Nullable_ULong ()",
"DataRowEnums_Nullable_ULong (null)",
"DataRowEnums_Nullable_ULong (Alfa)",
"DataRowEnums_Nullable_ULong (Beta)",
"DataRowEnums_Nullable_ULong (Gamma)",
@@ -275,23 +276,23 @@ public void ExecuteDataRowTests_Regular()
"DataRow1 (20)",
"DataRow1 (30)",
"DataRow1 (40)",
"DataRow2 (10,String parameter,True,False)",
"DataRow2 (20,String parameter,True,False)",
"DataRow2 (30,String parameter,True,False)",
"DataRow2 (40,String parameter,True,False)",
"DataRow2 (10,\"String parameter\",True,False)",
"DataRow2 (20,\"String parameter\",True,False)",
"DataRow2 (30,\"String parameter\",True,False)",
"DataRow2 (40,\"String parameter\",True,False)",
"DataRowTestDouble (10.01,20.01)",
"DataRowTestDouble (10.02,20.02)",
"DataRowTestMixed (1,10,10,10,10,10,10,10,10)",
"DataRowTestMixed (2,10,10,10,10,10,10,10,10)",
"DataRowTestMixed (3,10,10,10,10,10,10,10,10)",
"DataRowTestMixed (4,10,10,10,10,10,10,10,10)",
"NullValueInData ([email protected],abc123,)",
"NullValueInData ([email protected],abc123,/unit/test)",
"NullValue ()",
"OneStringArray ([])",
"TwoStringArrays ([],[1.4,message])",
"OneObjectArray ([,1])",
"TwoObjectArrays ([,1],[3])",
"DataRowTestMixed (1,10,10,10,10,10,10,10,\"10\")",
"DataRowTestMixed (2,10,10,10,10,10,10,10,\"10\")",
"DataRowTestMixed (3,10,10,10,10,10,10,10,\"10\")",
"DataRowTestMixed (4,10,10,10,10,10,10,10,\"10\")",
"NullValueInData (\"[email protected]\",\"abc123\",null)",
"NullValueInData (\"[email protected]\",\"abc123\",\"/unit/test\")",
"NullValue (null)",
"OneStringArray ([\"\"])",
"TwoStringArrays ([\"\"],[\"1.4\",\"message\"])",
"OneObjectArray ([\"\",1])",
"TwoObjectArrays ([\"\",1],[3])",
"ThreeObjectArrays ([1],[2],[3])",
"FourObjectArrays ([1],[2],[3],[4])",
"FiveObjectArrays ([1],[2],[3],[4],[5])",
@@ -312,6 +313,6 @@ public void ExecuteDataRowTests_Regular()
testResults,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
}
}
Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@ public void TestIdUniqueness_DataRowString_DefaultStrategy()
VerifyE2E.FailedTestCount(testResults, 0);
VerifyE2E.TestsPassed(
testResults,
"DataRowStringTests ()",
"DataRowStringTests ()",
"DataRowStringTests (null)",
"DataRowStringTests (\"\")",
"DataRowStringTests ( )",
"DataRowStringTests ( )");

Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@ public void TestIdUniqueness_DataRowString_FullyQualifiedStrategy()
VerifyE2E.FailedTestCount(testResults, 0);
VerifyE2E.TestsPassed(
testResults,
"DataRowStringTests ()",
"DataRowStringTests ()",
"DataRowStringTests (null)",
"DataRowStringTests (\"\")",
"DataRowStringTests ( )",
"DataRowStringTests ( )");

Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@ public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRow
InvokeVsTestForExecution([TestAssetName], testCaseFilter: "TestCategory~DataRowSimple");

ValidatePassedTestsContain(
"DataRowTestMethod (BaseString1)",
"DataRowTestMethod (BaseString2)",
"DataRowTestMethod (BaseString3)",
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
"DataRowTestMethod (\"BaseString1\")",
"DataRowTestMethod (\"BaseString2\")",
"DataRowTestMethod (\"BaseString3\")",
"DataRowTestMethod (\"DerivedString1\")",
"DataRowTestMethod (\"DerivedString2\")");

// 3 tests of BaseClass.DataRowTestMethod - 3 data row results and no parent result
// 2 tests of DerivedClass.DataRowTestMethod - 2 data row results and no parent result
@@ -41,8 +41,8 @@ public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_Simp
InvokeVsTestForExecution([TestAssetName], testCaseFilter: "FullyQualifiedName~DerivedClass&TestCategory~DataRowSimple");

ValidatePassedTestsContain(
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
"DataRowTestMethod (\"DerivedString1\")",
"DataRowTestMethod (\"DerivedString2\")");

// 2 tests of DerivedClass.DataRowTestMethod - 2 datarow result and no parent result
ValidatePassedTestsCount(2);
@@ -54,8 +54,8 @@ public void DataRowsExecuteWithRequiredAndOptionalParameters()

ValidatePassedTestsContain(
"DataRowTestMethodWithSomeOptionalParameters (123)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString1\")",
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString2\",\"DerivedOptionalString3\")");

// 3 tests of DerivedClass.DataRowTestMethodWithSomeOptionalParameters - 3 datarow result and no parent result
ValidatePassedTestsCount(3);
@@ -68,8 +68,8 @@ public void DataRowsExecuteWithAllOptionalParameters()
ValidatePassedTestsContain(
"DataRowTestMethodWithAllOptionalParameters ()",
"DataRowTestMethodWithAllOptionalParameters (123)",
"DataRowTestMethodWithAllOptionalParameters (123,DerivedOptionalString4)",
"DataRowTestMethodWithAllOptionalParameters (123,DerivedOptionalString5,DerivedOptionalString6)");
"DataRowTestMethodWithAllOptionalParameters (123,\"DerivedOptionalString4\")",
"DataRowTestMethodWithAllOptionalParameters (123,\"DerivedOptionalString5\",\"DerivedOptionalString6\")");

// 4 tests of DerivedClass.DataRowTestMethodWithAllOptionalParameters - 4 datarow result and no parent result
ValidatePassedTestsCount(4);
@@ -81,9 +81,9 @@ public void DataRowsExecuteWithParamsArrayParameter()

ValidatePassedTestsContain(
"DataRowTestMethodWithParamsParameters (2)",
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
"DataRowTestMethodWithParamsParameters (2,\"DerivedSingleParamsArg\")",
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\")",
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\",\"DerivedParamsArg3\")");

// 4 tests of DerivedClass.DataRowTestMethodWithParamsParameters - 4 datarow result and no parent result
ValidatePassedTestsCount(4);
@@ -97,7 +97,7 @@ public void DataRowsFailWhenInvalidArgumentsProvided()
false,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");

// 3 tests of DerivedClass.DataRowTestMethodFailsWithInvalidArguments - 3 datarow result and no parent result
ValidateFailedTestsCount(3);
@@ -136,35 +136,35 @@ public void ExecuteDataRowTests_Enums()
"DataRowEnum_ULong (Alfa)",
"DataRowEnum_ULong (Beta)",
"DataRowEnum_ULong (Gamma)",
"DataRowEnums_Nullable_SByte ()",
"DataRowEnums_Nullable_SByte (null)",
"DataRowEnums_Nullable_SByte (Alfa)",
"DataRowEnums_Nullable_SByte (Beta)",
"DataRowEnums_Nullable_SByte (Gamma)",
"DataRowEnums_Nullable_Byte ()",
"DataRowEnums_Nullable_Byte (null)",
"DataRowEnums_Nullable_Byte (Alfa)",
"DataRowEnums_Nullable_Byte (Beta)",
"DataRowEnums_Nullable_Byte (Gamma)",
"DataRowEnums_Nullable_Short ()",
"DataRowEnums_Nullable_Short (null)",
"DataRowEnums_Nullable_Short (Alfa)",
"DataRowEnums_Nullable_Short (Beta)",
"DataRowEnums_Nullable_Short (Gamma)",
"DataRowEnums_Nullable_UShort ()",
"DataRowEnums_Nullable_UShort (null)",
"DataRowEnums_Nullable_UShort (Alfa)",
"DataRowEnums_Nullable_UShort (Beta)",
"DataRowEnums_Nullable_UShort (Gamma)",
"DataRowEnums_Nullable_Int ()",
"DataRowEnums_Nullable_Int (null)",
"DataRowEnums_Nullable_Int (Alfa)",
"DataRowEnums_Nullable_Int (Beta)",
"DataRowEnums_Nullable_Int (Gamma)",
"DataRowEnums_Nullable_UInt ()",
"DataRowEnums_Nullable_UInt (null)",
"DataRowEnums_Nullable_UInt (Alfa)",
"DataRowEnums_Nullable_UInt (Beta)",
"DataRowEnums_Nullable_UInt (Gamma)",
"DataRowEnums_Nullable_Long ()",
"DataRowEnums_Nullable_Long (null)",
"DataRowEnums_Nullable_Long (Alfa)",
"DataRowEnums_Nullable_Long (Beta)",
"DataRowEnums_Nullable_Long (Gamma)",
"DataRowEnums_Nullable_ULong ()",
"DataRowEnums_Nullable_ULong (null)",
"DataRowEnums_Nullable_ULong (Alfa)",
"DataRowEnums_Nullable_ULong (Beta)",
"DataRowEnums_Nullable_ULong (Gamma)",
@@ -204,23 +204,23 @@ public void ExecuteRegular_DataRowTests()
"DataRow1 (20)",
"DataRow1 (30)",
"DataRow1 (40)",
"DataRow2 (10,String parameter,True,False)",
"DataRow2 (20,String parameter,True,False)",
"DataRow2 (30,String parameter,True,False)",
"DataRow2 (40,String parameter,True,False)",
"DataRow2 (10,\"String parameter\",True,False)",
"DataRow2 (20,\"String parameter\",True,False)",
"DataRow2 (30,\"String parameter\",True,False)",
"DataRow2 (40,\"String parameter\",True,False)",
"DataRowTestDouble (10.01,20.01)",
"DataRowTestDouble (10.02,20.02)",
"DataRowTestMixed (1,10,10,10,10,10,10,10,10)",
"DataRowTestMixed (2,10,10,10,10,10,10,10,10)",
"DataRowTestMixed (3,10,10,10,10,10,10,10,10)",
"DataRowTestMixed (4,10,10,10,10,10,10,10,10)",
"NullValueInData ([email protected],abc123,)",
"NullValueInData ([email protected],abc123,/unit/test)",
"NullValue ()",
"OneStringArray ([])",
"TwoStringArrays ([],[1.4,message])",
"OneObjectArray ([,1])",
"TwoObjectArrays ([,1],[3])",
"DataRowTestMixed (1,10,10,10,10,10,10,10,\"10\")",
"DataRowTestMixed (2,10,10,10,10,10,10,10,\"10\")",
"DataRowTestMixed (3,10,10,10,10,10,10,10,\"10\")",
"DataRowTestMixed (4,10,10,10,10,10,10,10,\"10\")",
"NullValueInData (\"[email protected]\",\"abc123\",null)",
"NullValueInData (\"[email protected]\",\"abc123\",\"/unit/test\")",
"NullValue (null)",
"OneStringArray ([\"\"])",
"TwoStringArrays ([\"\"],[\"1.4\",\"message\"])",
"OneObjectArray ([\"\",1])",
"TwoObjectArrays ([\"\",1],[3])",
"ThreeObjectArrays ([1],[2],[3])",
"FourObjectArrays ([1],[2],[3],[4])",
"FiveObjectArrays ([1],[2],[3],[4],[5])",
@@ -241,6 +241,6 @@ public void ExecuteRegular_DataRowTests()
false,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
}
}
Loading