Skip to content

Commit 3937b03

Browse files
MichelZEvangelink
andauthored
Improve display name for string and char (#3082)
Co-authored-by: Amaury Levé <[email protected]> Co-authored-by: Amaury Levé <[email protected]>
1 parent 31440b4 commit 3937b03

File tree

10 files changed

+130
-121
lines changed

10 files changed

+130
-121
lines changed

src/TestFramework/TestFramework/Attributes/DataSource/DataRowAttribute.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,24 @@ public DataRowAttribute(params object?[]? data)
9595
/// </summary>
9696
private static string? GetObjectString(object? obj)
9797
{
98+
if (TestIdGenerationStrategy != TestIdGenerationStrategy.FullyQualified)
99+
{
100+
return obj?.ToString();
101+
}
102+
98103
if (obj == null)
99104
{
100-
return null;
105+
return "null";
101106
}
102107

103-
if (TestIdGenerationStrategy != TestIdGenerationStrategy.FullyQualified
104-
|| !obj.GetType().IsArray)
108+
if (!obj.GetType().IsArray)
105109
{
106-
return obj.ToString();
110+
return obj switch
111+
{
112+
string s => $"\"{s}\"",
113+
char c => $"'{c}'",
114+
_ => obj.ToString(),
115+
};
107116
}
108117

109118
// We need to box the object here so that we can support value types

test/IntegrationTests/MSTest.IntegrationTests/ClsTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public void TestsAreRun()
2525
testResults,
2626
"TestMethod",
2727
"IntDataRow (10)",
28-
"StringDataRow (some string)",
29-
"StringDataRow2 (some string)",
30-
"StringDataRow2 (some other string)");
28+
"StringDataRow (\"some string\")",
29+
"StringDataRow2 (\"some string\")",
30+
"StringDataRow2 (\"some other string\")");
3131
}
3232
}

test/IntegrationTests/MSTest.IntegrationTests/Parameterized tests/DataExtensibilityTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ public void ExecuteCustomTestExtensibilityWithTestDataTests()
8181
// Assert
8282
VerifyE2E.TestsPassed(
8383
testResults,
84-
"CustomTestMethod2 (B)",
85-
"CustomTestMethod2 (B)",
86-
"CustomTestMethod2 (B)");
84+
"CustomTestMethod2 (\"B\")",
85+
"CustomTestMethod2 (\"B\")",
86+
"CustomTestMethod2 (\"B\")");
8787

8888
VerifyE2E.TestsFailed(
8989
testResults,
90-
"CustomTestMethod2 (A)",
91-
"CustomTestMethod2 (A)",
92-
"CustomTestMethod2 (A)",
93-
"CustomTestMethod2 (C)",
94-
"CustomTestMethod2 (C)",
95-
"CustomTestMethod2 (C)");
90+
"CustomTestMethod2 (\"A\")",
91+
"CustomTestMethod2 (\"A\")",
92+
"CustomTestMethod2 (\"A\")",
93+
"CustomTestMethod2 (\"C\")",
94+
"CustomTestMethod2 (\"C\")",
95+
"CustomTestMethod2 (\"C\")");
9696
}
9797
}

test/IntegrationTests/MSTest.IntegrationTests/Parameterized tests/DataRowTests.cs

+39-39
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public void ExecuteOnlyDerivedClassDataRowsWhenBothBaseAndDerivedClassHasDataRow
2121
// Assert
2222
VerifyE2E.TestsPassed(
2323
testResults,
24-
"DataRowTestMethod (BaseString1)",
25-
"DataRowTestMethod (BaseString2)",
26-
"DataRowTestMethod (BaseString3)",
27-
"DataRowTestMethod (DerivedString1)",
28-
"DataRowTestMethod (DerivedString2)");
24+
"DataRowTestMethod (\"BaseString1\")",
25+
"DataRowTestMethod (\"BaseString2\")",
26+
"DataRowTestMethod (\"BaseString3\")",
27+
"DataRowTestMethod (\"DerivedString1\")",
28+
"DataRowTestMethod (\"DerivedString2\")");
2929
}
3030

3131
public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_SimpleDataRows()
@@ -40,8 +40,8 @@ public void ExecuteOnlyDerivedClassDataRowsWhenItOverridesBaseClassDataRows_Simp
4040
// Assert
4141
VerifyE2E.TestsPassed(
4242
testResults,
43-
"DataRowTestMethod (DerivedString1)",
44-
"DataRowTestMethod (DerivedString2)");
43+
"DataRowTestMethod (\"DerivedString1\")",
44+
"DataRowTestMethod (\"DerivedString2\")");
4545
}
4646

4747
public void DataRowsExecuteWithRequiredAndOptionalParameters()
@@ -57,8 +57,8 @@ public void DataRowsExecuteWithRequiredAndOptionalParameters()
5757
VerifyE2E.TestsPassed(
5858
testResults,
5959
"DataRowTestMethodWithSomeOptionalParameters (123)",
60-
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString1)",
61-
"DataRowTestMethodWithSomeOptionalParameters (123,DerivedOptionalString2,DerivedOptionalString3)");
60+
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString1\")",
61+
"DataRowTestMethodWithSomeOptionalParameters (123,\"DerivedOptionalString2\",\"DerivedOptionalString3\")");
6262
}
6363

6464
public void DataRowsExecuteWithParamsArrayParameter()
@@ -74,9 +74,9 @@ public void DataRowsExecuteWithParamsArrayParameter()
7474
VerifyE2E.TestsPassed(
7575
testResults,
7676
"DataRowTestMethodWithParamsParameters (2)",
77-
"DataRowTestMethodWithParamsParameters (2,DerivedSingleParamsArg)",
78-
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2)",
79-
"DataRowTestMethodWithParamsParameters (2,DerivedParamsArg1,DerivedParamsArg2,DerivedParamsArg3)");
77+
"DataRowTestMethodWithParamsParameters (2,\"DerivedSingleParamsArg\")",
78+
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\")",
79+
"DataRowTestMethodWithParamsParameters (2,\"DerivedParamsArg1\",\"DerivedParamsArg2\",\"DerivedParamsArg3\")");
8080
}
8181

8282
public void DataRowsFailWhenInvalidArgumentsProvided()
@@ -93,7 +93,7 @@ public void DataRowsFailWhenInvalidArgumentsProvided()
9393
testResults,
9494
"DataRowTestMethodFailsWithInvalidArguments ()",
9595
"DataRowTestMethodFailsWithInvalidArguments (2)",
96-
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
96+
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
9797
}
9898

9999
public void DataRowsShouldSerializeDoublesProperly()
@@ -124,7 +124,7 @@ public void DataRowsShouldSerializeMixedTypesProperly()
124124
// Assert
125125
VerifyE2E.TestsPassed(
126126
testResults,
127-
"DataRowTestMixed (10,10,10,10,10,10,10,10)");
127+
"DataRowTestMixed (10,10,10,10,10,10,10,\"10\")");
128128
}
129129

130130
public void DataRowsShouldSerializeEnumsProperly()
@@ -139,7 +139,7 @@ public void DataRowsShouldSerializeEnumsProperly()
139139
// Assert
140140
VerifyE2E.TestsPassed(
141141
testResults,
142-
"DataRowEnums ()",
142+
"DataRowEnums (null)",
143143
"DataRowEnums (Alfa)",
144144
"DataRowEnums (Beta)",
145145
"DataRowEnums (Gamma)");
@@ -202,35 +202,35 @@ public void ExecuteDataRowTests_Enums()
202202
"DataRowEnum_ULong (Alfa)",
203203
"DataRowEnum_ULong (Beta)",
204204
"DataRowEnum_ULong (Gamma)",
205-
"DataRowEnums_Nullable_SByte ()",
205+
"DataRowEnums_Nullable_SByte (null)",
206206
"DataRowEnums_Nullable_SByte (Alfa)",
207207
"DataRowEnums_Nullable_SByte (Beta)",
208208
"DataRowEnums_Nullable_SByte (Gamma)",
209-
"DataRowEnums_Nullable_Byte ()",
209+
"DataRowEnums_Nullable_Byte (null)",
210210
"DataRowEnums_Nullable_Byte (Alfa)",
211211
"DataRowEnums_Nullable_Byte (Beta)",
212212
"DataRowEnums_Nullable_Byte (Gamma)",
213-
"DataRowEnums_Nullable_Short ()",
213+
"DataRowEnums_Nullable_Short (null)",
214214
"DataRowEnums_Nullable_Short (Alfa)",
215215
"DataRowEnums_Nullable_Short (Beta)",
216216
"DataRowEnums_Nullable_Short (Gamma)",
217-
"DataRowEnums_Nullable_UShort ()",
217+
"DataRowEnums_Nullable_UShort (null)",
218218
"DataRowEnums_Nullable_UShort (Alfa)",
219219
"DataRowEnums_Nullable_UShort (Beta)",
220220
"DataRowEnums_Nullable_UShort (Gamma)",
221-
"DataRowEnums_Nullable_Int ()",
221+
"DataRowEnums_Nullable_Int (null)",
222222
"DataRowEnums_Nullable_Int (Alfa)",
223223
"DataRowEnums_Nullable_Int (Beta)",
224224
"DataRowEnums_Nullable_Int (Gamma)",
225-
"DataRowEnums_Nullable_UInt ()",
225+
"DataRowEnums_Nullable_UInt (null)",
226226
"DataRowEnums_Nullable_UInt (Alfa)",
227227
"DataRowEnums_Nullable_UInt (Beta)",
228228
"DataRowEnums_Nullable_UInt (Gamma)",
229-
"DataRowEnums_Nullable_Long ()",
229+
"DataRowEnums_Nullable_Long (null)",
230230
"DataRowEnums_Nullable_Long (Alfa)",
231231
"DataRowEnums_Nullable_Long (Beta)",
232232
"DataRowEnums_Nullable_Long (Gamma)",
233-
"DataRowEnums_Nullable_ULong ()",
233+
"DataRowEnums_Nullable_ULong (null)",
234234
"DataRowEnums_Nullable_ULong (Alfa)",
235235
"DataRowEnums_Nullable_ULong (Beta)",
236236
"DataRowEnums_Nullable_ULong (Gamma)",
@@ -275,23 +275,23 @@ public void ExecuteDataRowTests_Regular()
275275
"DataRow1 (20)",
276276
"DataRow1 (30)",
277277
"DataRow1 (40)",
278-
"DataRow2 (10,String parameter,True,False)",
279-
"DataRow2 (20,String parameter,True,False)",
280-
"DataRow2 (30,String parameter,True,False)",
281-
"DataRow2 (40,String parameter,True,False)",
278+
"DataRow2 (10,\"String parameter\",True,False)",
279+
"DataRow2 (20,\"String parameter\",True,False)",
280+
"DataRow2 (30,\"String parameter\",True,False)",
281+
"DataRow2 (40,\"String parameter\",True,False)",
282282
"DataRowTestDouble (10.01,20.01)",
283283
"DataRowTestDouble (10.02,20.02)",
284-
"DataRowTestMixed (1,10,10,10,10,10,10,10,10)",
285-
"DataRowTestMixed (2,10,10,10,10,10,10,10,10)",
286-
"DataRowTestMixed (3,10,10,10,10,10,10,10,10)",
287-
"DataRowTestMixed (4,10,10,10,10,10,10,10,10)",
288-
"NullValueInData ([email protected],abc123,)",
289-
"NullValueInData ([email protected],abc123,/unit/test)",
290-
"NullValue ()",
291-
"OneStringArray ([])",
292-
"TwoStringArrays ([],[1.4,message])",
293-
"OneObjectArray ([,1])",
294-
"TwoObjectArrays ([,1],[3])",
284+
"DataRowTestMixed (1,10,10,10,10,10,10,10,\"10\")",
285+
"DataRowTestMixed (2,10,10,10,10,10,10,10,\"10\")",
286+
"DataRowTestMixed (3,10,10,10,10,10,10,10,\"10\")",
287+
"DataRowTestMixed (4,10,10,10,10,10,10,10,\"10\")",
288+
"NullValueInData (\"[email protected]\",\"abc123\",null)",
289+
"NullValueInData (\"[email protected]\",\"abc123\",\"/unit/test\")",
290+
"NullValue (null)",
291+
"OneStringArray ([\"\"])",
292+
"TwoStringArrays ([\"\"],[\"1.4\",\"message\"])",
293+
"OneObjectArray ([\"\",1])",
294+
"TwoObjectArrays ([\"\",1],[3])",
295295
"ThreeObjectArrays ([1],[2],[3])",
296296
"FourObjectArrays ([1],[2],[3],[4])",
297297
"FiveObjectArrays ([1],[2],[3],[4],[5])",
@@ -312,6 +312,6 @@ public void ExecuteDataRowTests_Regular()
312312
testResults,
313313
"DataRowTestMethodFailsWithInvalidArguments ()",
314314
"DataRowTestMethodFailsWithInvalidArguments (2)",
315-
"DataRowTestMethodFailsWithInvalidArguments (2,DerivedRequiredArgument,DerivedOptionalArgument,DerivedExtraArgument)");
315+
"DataRowTestMethodFailsWithInvalidArguments (2,\"DerivedRequiredArgument\",\"DerivedOptionalArgument\",\"DerivedExtraArgument\")");
316316
}
317317
}

test/IntegrationTests/MSTest.IntegrationTests/TestId.DefaultStrategy.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public void TestIdUniqueness_DataRowString_DefaultStrategy()
4545
VerifyE2E.FailedTestCount(testResults, 0);
4646
VerifyE2E.TestsPassed(
4747
testResults,
48-
"DataRowStringTests ()",
49-
"DataRowStringTests ()",
50-
"DataRowStringTests ( )",
51-
"DataRowStringTests ( )");
48+
"DataRowStringTests (null)",
49+
"DataRowStringTests (\"\")",
50+
"DataRowStringTests (\" \")",
51+
"DataRowStringTests (\" \")");
5252

5353
// We cannot assert the expected ID as it is path dependent
5454
testResults.Select(x => x.TestCase.Id.ToString()).Should().OnlyHaveUniqueItems();

test/IntegrationTests/MSTest.IntegrationTests/TestId.FullyQualifiedStrategy.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public void TestIdUniqueness_DataRowString_FullyQualifiedStrategy()
4545
VerifyE2E.FailedTestCount(testResults, 0);
4646
VerifyE2E.TestsPassed(
4747
testResults,
48-
"DataRowStringTests ()",
49-
"DataRowStringTests ()",
50-
"DataRowStringTests ( )",
51-
"DataRowStringTests ( )");
48+
"DataRowStringTests (null)",
49+
"DataRowStringTests (\"\")",
50+
"DataRowStringTests (\" \")",
51+
"DataRowStringTests (\" \")");
5252

5353
// We cannot assert the expected ID as it is path dependent
5454
testResults.Select(x => x.TestCase.Id.ToString()).Should().OnlyHaveUniqueItems();

test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/Parameterized tests/DataExtensibilityTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ public void ExecuteCustomTestExtensibilityWithTestDataTests()
6565
InvokeVsTestForExecution([TestAssetName], testCaseFilter: "FullyQualifiedName~CustomTestExTests.CustomTestMethod2");
6666

6767
ValidatePassedTests(
68-
"CustomTestMethod2 (B)",
69-
"CustomTestMethod2 (B)",
70-
"CustomTestMethod2 (B)");
68+
"CustomTestMethod2 (\"B\")",
69+
"CustomTestMethod2 (\"B\")",
70+
"CustomTestMethod2 (\"B\")");
7171
ValidateFailedTestsCount(6);
7272
ValidateFailedTestsContain(
7373
true,
74-
"CustomTestMethod2 (A)",
75-
"CustomTestMethod2 (A)",
76-
"CustomTestMethod2 (A)",
77-
"CustomTestMethod2 (C)",
78-
"CustomTestMethod2 (C)",
79-
"CustomTestMethod2 (C)");
74+
"CustomTestMethod2 (\"A\")",
75+
"CustomTestMethod2 (\"A\")",
76+
"CustomTestMethod2 (\"A\")",
77+
"CustomTestMethod2 (\"C\")",
78+
"CustomTestMethod2 (\"C\")",
79+
"CustomTestMethod2 (\"C\")");
8080
}
8181
}

0 commit comments

Comments
 (0)