-
Notifications
You must be signed in to change notification settings - Fork 278
Add non-serialization strategy for data unfolding #4467
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,22 +169,11 @@ internal List<TestResult> RunTestMethod() | |
|
||
bool isDataDriven = false; | ||
var parentStopwatch = Stopwatch.StartNew(); | ||
if (_test.DataType == DynamicDataType.ITestDataSource) | ||
if (TryExecuteITestDataSource(results)) | ||
{ | ||
if (_test.TestDataSourceIgnoreMessage is not null) | ||
{ | ||
return [new() { Outcome = UTF.UnitTestOutcome.Ignored, IgnoreReason = _test.TestDataSourceIgnoreMessage }]; | ||
} | ||
|
||
object?[]? data = DataSerializationHelper.Deserialize(_test.SerializedData); | ||
TestResult[] testResults = ExecuteTestWithDataSource(null, data); | ||
results.AddRange(testResults); | ||
} | ||
else if (TryExecuteDataSourceBasedTests(results)) | ||
{ | ||
isDataDriven = true; | ||
} | ||
else if (TryExecuteFoldedDataDrivenTests(results)) | ||
else if (TryExecuteDataSourceBasedTests(results) | ||
|| TryExecuteFoldedDataDrivenTests(results)) | ||
{ | ||
isDataDriven = true; | ||
} | ||
|
@@ -526,4 +515,42 @@ private static List<TestResult> UpdateResultsWithParentInfo( | |
|
||
return updatedResults; | ||
} | ||
|
||
private bool TryExecuteITestDataSource(List<TestResult> results) | ||
{ | ||
if (_test.DataType != DynamicDataType.ITestDataSource) | ||
{ | ||
return false; | ||
} | ||
|
||
UTF.ITestDataSource? dataSource; | ||
object?[]? data; | ||
if (_test.SerializedData?.Length == 3) | ||
{ | ||
if (!Enum.TryParse(_test.SerializedData[0], out TestDataSourceUnfoldingStrategy _) | ||
|| !int.TryParse(_test.SerializedData[1], out int dataSourceIndex) | ||
|| !int.TryParse(_test.SerializedData[2], out int dataIndex)) | ||
{ | ||
throw ApplicationStateGuard.Unreachable(); | ||
} | ||
|
||
dataSource = _testMethodInfo.GetAttributes<Attribute>(false)?.OfType<UTF.ITestDataSource>().Skip(dataSourceIndex).FirstOrDefault(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Runtime team just told me not to rely on guaranteed reflection order. I'll try to see what other option we have. Given that this is currently always working fine, I'd vote for adding a comment and moving on with the PR. |
||
if (dataSource is null) | ||
{ | ||
throw ApplicationStateGuard.Unreachable(); | ||
} | ||
|
||
data = dataSource.GetData(_testMethodInfo.MethodInfo).Skip(dataIndex).FirstOrDefault(); | ||
} | ||
else | ||
{ | ||
dataSource = null; | ||
data = DataSerializationHelper.Deserialize(_test.SerializedData); | ||
} | ||
|
||
TestResult[] testResults = ExecuteTestWithDataSource(dataSource, data); | ||
results.AddRange(testResults); | ||
|
||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.ComponentModel; | ||
|
||
namespace Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
/// <summary> | ||
|
@@ -22,17 +24,33 @@ public enum TestDataSourceUnfoldingStrategy : byte | |
/// <summary> | ||
/// MSTest will decide whether to unfold the parameterized test based on value from the assembly level attribute | ||
/// <see cref="TestDataSourceOptionsAttribute" />. If no assembly level attribute is specified, then the default | ||
/// configuration is to unfold. | ||
/// configuration is to unfold using <see cref="System.Runtime.Serialization.Json.DataContractJsonSerializer"/>. | ||
/// </summary> | ||
Auto, | ||
|
||
/// <summary> | ||
/// Each data row is treated as a separate test case. | ||
/// </summary> | ||
/// <inheritdoc cref="UnfoldUsingDataContractJsonSerializer"/> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[Obsolete("Use 'UnfoldUsingDataContractJsonSerializer' instead")] | ||
Evangelink marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Unfold, | ||
|
||
/// <summary> | ||
/// The parameterized test is not unfolded; all data rows are treated as a single test case. | ||
/// </summary> | ||
Fold, | ||
|
||
/// <summary> | ||
/// Each data row is treated as a separate test case, and the data is unfolded using | ||
/// <see cref="System.Runtime.Serialization.Json.DataContractJsonSerializer"/>. | ||
/// </summary> | ||
UnfoldUsingDataContractJsonSerializer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make this the same numeric value as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's probably not important, is it? |
||
|
||
/// <summary> | ||
/// Each data row is treated as a separate test case, and the data is unfolded using the data | ||
/// source index and data index. | ||
/// </summary> | ||
/// <remarks> | ||
/// Using this strategy will alter the test ID if the data source is reordered, as it depends | ||
/// on the index of the data. This may affect the ability to track test cases over time. | ||
/// </remarks> | ||
UnfoldUsingDataIndex, | ||
} |
Uh oh!
There was an error while loading. Please reload this page.