Skip to content

Commit cc1c3cd

Browse files
youssef-backport-botYoussef1313Evangelink
authored
[rel/3.8] Follow-up to ignore fix (#5043)
Co-authored-by: Youssef1313 <youssefvictor00@gmail.com> Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
1 parent 193598b commit cc1c3cd

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ internal TestResult[] RunTestMethod()
170170
var parentStopwatch = Stopwatch.StartNew();
171171
if (_test.DataType == DynamicDataType.ITestDataSource)
172172
{
173-
if (!string.IsNullOrEmpty(_test.TestDataSourceIgnoreMessage))
173+
if (_test.TestDataSourceIgnoreMessage is not null)
174174
{
175175
_testContext.SetOutcome(UTF.UnitTestOutcome.Ignored);
176176
return [TestResult.CreateIgnoredResult(_test.TestDataSourceIgnoreMessage)];
@@ -269,7 +269,7 @@ private bool TryExecuteFoldedDataDrivenTests(List<TestResult> results)
269269

270270
foreach (UTF.ITestDataSource testDataSource in testDataSources)
271271
{
272-
if (testDataSource is ITestDataSourceIgnoreCapability { IgnoreMessage: { Length: > 0 } ignoreMessage })
272+
if (testDataSource is ITestDataSourceIgnoreCapability { IgnoreMessage: { } ignoreMessage })
273273
{
274274
results.Add(TestResult.CreateIgnoredResult(ignoreMessage));
275275
continue;

src/Adapter/MSTest.TestAdapter/ObjectModel/TestMethod.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,7 @@ public string? DeclaringClassFullName
153153
/// Gets or sets the test data source ignore message.
154154
/// </summary>
155155
/// <remarks>
156-
/// The test is ignored if this is set to non-null and non-empty string.
157-
/// If set to empty string, the test is considered as not ignored.
158-
/// In VSTest, when tests are expanded during discovery, we end up reading
159-
/// this property as empty string, even though it was set to null.
160-
/// (probably some serialization issue on VSTest side)
161-
/// So, we treat null and empty string the same.
156+
/// The test is ignored if this is set to non-null.
162157
/// </remarks>
163158
internal string? TestDataSourceIgnoreMessage { get; set; }
164159

src/Adapter/MSTest.TestAdapter/ObjectModel/UnitTestElement.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ internal TestCase ToTestCase()
195195

196196
testCase.SetPropertyValue(Constants.TestDynamicDataTypeProperty, (int)TestMethod.DataType);
197197
testCase.SetPropertyValue(Constants.TestDynamicDataProperty, data);
198-
testCase.SetPropertyValue(Constants.TestDataSourceIgnoreMessageProperty, TestMethod.TestDataSourceIgnoreMessage);
198+
// VSTest serialization doesn't handle null so instead don't set the property so that it's deserialized as null
199+
if (TestMethod.TestDataSourceIgnoreMessage is not null)
200+
{
201+
testCase.SetPropertyValue(Constants.TestDataSourceIgnoreMessageProperty, TestMethod.TestDataSourceIgnoreMessage);
202+
}
199203
}
200204

201205
SetTestCaseId(testCase, testFullName);

src/TestFramework/TestFramework/Interfaces/ITestDataSourceIgnoreCapability.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
99
public interface ITestDataSourceIgnoreCapability
1010
{
1111
/// <summary>
12-
/// Gets or sets a reason to ignore the test data source. Setting the property to non-null and non-empty string value will ignore the test data source.
12+
/// Gets or sets a reason to ignore the test data source. Setting the property to non-null value will ignore the test data source.
1313
/// </summary>
1414
string? IgnoreMessage { get; set; }
1515
}

0 commit comments

Comments
 (0)