Skip to content

Commit

Permalink
Improve display name for string and char (#3082)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Co-authored-by: Amaury Levé <amaury.leve@gmail.com>
  • Loading branch information
3 people authored Jun 10, 2024
1 parent 31440b4 commit 3937b03
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void TestsAreRun()
testResults,
"TestMethod",
"IntDataRow (10)",
"StringDataRow (some string)",
"StringDataRow2 (some string)",
"StringDataRow2 (some other string)");
"StringDataRow (\"some string\")",
"StringDataRow2 (\"some string\")",
"StringDataRow2 (\"some other string\")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ public void ExecuteCustomTestExtensibilityWithTestDataTests()
// Assert
VerifyE2E.TestsPassed(
testResults,
"CustomTestMethod2 (B)",
"CustomTestMethod2 (B)",
"CustomTestMethod2 (B)");
"CustomTestMethod2 (\"B\")",
"CustomTestMethod2 (\"B\")",
"CustomTestMethod2 (\"B\")");

VerifyE2E.TestsFailed(
testResults,
"CustomTestMethod2 (A)",
"CustomTestMethod2 (A)",
"CustomTestMethod2 (A)",
"CustomTestMethod2 (C)",
"CustomTestMethod2 (C)",
"CustomTestMethod2 (C)");
"CustomTestMethod2 (\"A\")",
"CustomTestMethod2 (\"A\")",
"CustomTestMethod2 (\"A\")",
"CustomTestMethod2 (\"C\")",
"CustomTestMethod2 (\"C\")",
"CustomTestMethod2 (\"C\")");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,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()
Expand All @@ -40,8 +40,8 @@ public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_Simp
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowTestMethod (DerivedString1)",
"DataRowTestMethod (DerivedString2)");
"DataRowTestMethod (\"DerivedString1\")",
"DataRowTestMethod (\"DerivedString2\")");
}

public void DataRowsExecuteWithRequiredAndOptionalParameters()
Expand All @@ -57,8 +57,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()
Expand All @@ -74,9 +74,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()
Expand All @@ -93,7 +93,7 @@ public void DataRowsFailWhenInvalidArgumentsProvided()
testResults,
"DataRowTestMethodFailsWithInvalidArguments ()",
"DataRowTestMethodFailsWithInvalidArguments (2)",
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
}

public void DataRowsShouldSerializeDoublesProperly()
Expand Down Expand Up @@ -124,7 +124,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()
Expand All @@ -139,7 +139,7 @@ public void DataRowsShouldSerializeEnumsProperly()
// Assert
VerifyE2E.TestsPassed(
testResults,
"DataRowEnums ()",
"DataRowEnums (null)",
"DataRowEnums (Alfa)",
"DataRowEnums (Beta)",
"DataRowEnums (Gamma)");
Expand Down Expand Up @@ -202,35 +202,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)",
Expand Down Expand Up @@ -275,23 +275,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 (john.doe@example.com,abc123,)",
"NullValueInData (john.doe@example.com,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 (\"john.doe@example.com\",\"abc123\",null)",
"NullValueInData (\"john.doe@example.com\",\"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])",
Expand All @@ -312,6 +312,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
Expand Up @@ -45,10 +45,10 @@ public void TestIdUniqueness_DataRowString_DefaultStrategy()
VerifyE2E.FailedTestCount(testResults, 0);
VerifyE2E.TestsPassed(
testResults,
"DataRowStringTests ()",
"DataRowStringTests ()",
"DataRowStringTests ( )",
"DataRowStringTests ( )");
"DataRowStringTests (null)",
"DataRowStringTests (\"\")",
"DataRowStringTests (\" \")",
"DataRowStringTests (\" \")");

// We cannot assert the expected ID as it is path dependent
testResults.Select(x => x.TestCase.Id.ToString()).Should().OnlyHaveUniqueItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public void TestIdUniqueness_DataRowString_FullyQualifiedStrategy()
VerifyE2E.FailedTestCount(testResults, 0);
VerifyE2E.TestsPassed(
testResults,
"DataRowStringTests ()",
"DataRowStringTests ()",
"DataRowStringTests ( )",
"DataRowStringTests ( )");
"DataRowStringTests (null)",
"DataRowStringTests (\"\")",
"DataRowStringTests (\" \")",
"DataRowStringTests (\" \")");

// We cannot assert the expected ID as it is path dependent
testResults.Select(x => x.TestCase.Id.ToString()).Should().OnlyHaveUniqueItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public void ExecuteCustomTestExtensibilityWithTestDataTests()
InvokeVsTestForExecution([TestAssetName], testCaseFilter: "FullyQualifiedName~CustomTestExTests.CustomTestMethod2");

ValidatePassedTests(
"CustomTestMethod2 (B)",
"CustomTestMethod2 (B)",
"CustomTestMethod2 (B)");
"CustomTestMethod2 (\"B\")",
"CustomTestMethod2 (\"B\")",
"CustomTestMethod2 (\"B\")");
ValidateFailedTestsCount(6);
ValidateFailedTestsContain(
true,
"CustomTestMethod2 (A)",
"CustomTestMethod2 (A)",
"CustomTestMethod2 (A)",
"CustomTestMethod2 (C)",
"CustomTestMethod2 (C)",
"CustomTestMethod2 (C)");
"CustomTestMethod2 (\"A\")",
"CustomTestMethod2 (\"A\")",
"CustomTestMethod2 (\"A\")",
"CustomTestMethod2 (\"C\")",
"CustomTestMethod2 (\"C\")",
"CustomTestMethod2 (\"C\")");
}
}
Loading

0 comments on commit 3937b03

Please sign in to comment.