Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Dec 27, 2024
1 parent 158cba5 commit 1bae8e7
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Adapter/MSTest.TestAdapter/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ internal static class Constants
internal static readonly TestProperty TestDynamicDataProperty = TestProperty.Register("MSTest.DynamicData", "DynamicData", typeof(string[]), TestPropertyAttributes.Hidden, typeof(TestCase));

internal static readonly TestProperty TestIdGenerationStrategyProperty = TestProperty.Register("MSTest.TestIdGenerationStrategy", "TestIdGenerationStrategy", typeof(int), TestPropertyAttributes.Hidden, typeof(TestCase));

internal static readonly TestProperty TestDataSourceIgnoreReasonProperty = TestProperty.Register("MSTest.TestDataSourceIgnoreReasonProperty", "TestDataSourceIgnoreReasonProperty", typeof(string), TestPropertyAttributes.Hidden, typeof(TestCase));
#endregion

#region Private Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static bool TryUnfoldITestDataSource(ITestDataSource dataSource, TestDat
// This code is to discover tests. To run the tests code is in TestMethodRunner.ExecuteDataSourceBasedTests.
// Any change made here should be reflected in TestMethodRunner.ExecuteDataSourceBasedTests as well.
data = dataSource.GetData(methodInfo);
string? ignoreReason = (dataSource as ITestDataSourceIgnoreCapability)?.Ignore;
string? testDataSourceIgnoreReason = (dataSource as ITestDataSourceIgnoreCapability)?.Ignore;

if (!data.Any())
{
Expand All @@ -435,6 +435,7 @@ private static bool TryUnfoldITestDataSource(ITestDataSource dataSource, TestDat
UnitTestElement discoveredTest = test.Clone();
// Make the test not data driven, because it had no data.
discoveredTest.TestMethod.DataType = DynamicDataType.None;
discoveredTest.TestMethod.TestDataSourceIgnoreReason = testDataSourceIgnoreReason;
discoveredTest.DisplayName = dataSource.GetDisplayName(methodInfo, null) ?? discoveredTest.DisplayName;

tests.Add(discoveredTest);
Expand Down Expand Up @@ -468,6 +469,7 @@ private static bool TryUnfoldITestDataSource(ITestDataSource dataSource, TestDat
try
{
discoveredTest.TestMethod.SerializedData = DataSerializationHelper.Serialize(d);
discoveredTest.TestMethod.TestDataSourceIgnoreReason = testDataSourceIgnoreReason;
discoveredTest.TestMethod.DataType = DynamicDataType.ITestDataSource;
}
catch (SerializationException ex)
Expand Down
19 changes: 19 additions & 0 deletions src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ internal UnitTestResult[] RunTestMethod()
{
if (_test.DataType == DynamicDataType.ITestDataSource)
{
if (_test.TestDataSourceIgnoreReason is not null)
{
return [new(UnitTestOutcome.Ignored, _test.TestDataSourceIgnoreReason)];
}

object?[]? data = DataSerializationHelper.Deserialize(_test.SerializedData);
TestResult[] testResults = ExecuteTestWithDataSource(null, data);
results.AddRange(testResults);
Expand Down Expand Up @@ -306,6 +311,20 @@ private bool ExecuteDataSourceBasedTests(List<TestResult> results)
foreach (UTF.ITestDataSource testDataSource in testDataSources)
{
isDataDriven = true;

if (testDataSource is ITestDataSourceIgnoreCapability { Ignore: { } ignoreReason })
{
results.Add(new()
{
// This is closest to ignore. This enum doesn't have a value specific to Ignore.
// It may be a better idea to add a value there, but the enum is public and we need to think more carefully before adding the API.
// For now, TestResultExtensions.ToUnitTestResults method will convert this to Ignored value of ObjectModel enum when IgnoreReason is non-null.
Outcome = UTF.UnitTestOutcome.NotRunnable,
IgnoreReason = ignoreReason,
});
continue;
}

IEnumerable<object?[]>? dataSource;

// This code is to execute tests. To discover the tests code is in AssemblyEnumerator.ProcessTestDataSourceTests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string

testMethod.DataType = dataType;
testMethod.SerializedData = data;
testMethod.TestDataSourceIgnoreReason = testCase.GetPropertyValue(Constants.TestDataSourceIgnoreReasonProperty) as string;
}

if (testCase.GetPropertyValue(Constants.DeclaringClassNameProperty) is string declaringClassName && declaringClassName != testClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ internal static UnitTestResult[] ToUnitTestResults(this IReadOnlyCollection<UTF.
int i = 0;
foreach (UTF.TestResult testResult in testResults)
{
var outcome = testResult.Outcome.ToUnitTestOutcome();
UnitTestOutcome outcome = testResult.IgnoreReason is not null
? UnitTestOutcome.Ignored
: testResult.Outcome.ToUnitTestOutcome();

UnitTestResult unitTestResult = testResult.TestFailureException is { } testFailureException
? new UnitTestResult(
Expand All @@ -38,6 +40,12 @@ internal static UnitTestResult[] ToUnitTestResults(this IReadOnlyCollection<UTF.
testFailureException.TryGetMessage(),
testFailureException is TestFailedException testException ? testException.StackTraceInformation : testFailureException.TryGetStackTraceInformation()))
: new UnitTestResult { Outcome = outcome };

if (testResult.IgnoreReason is not null)
{
unitTestResult.ErrorMessage = testResult.IgnoreReason;
}

unitTestResult.StandardOut = testResult.LogOutput;
unitTestResult.StandardError = testResult.LogError;
unitTestResult.DebugTrace = testResult.DebugTrace;
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/MSTest.TestAdapter/ObjectModel/TestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public string? DeclaringClassFullName
/// </summary>
internal string?[]? SerializedData { get; set; }

internal string? TestDataSourceIgnoreReason { get; set; }

/// <summary>
/// Gets or sets the test group set during discovery.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ internal TestCase ToTestCase()

testCase.SetPropertyValue(Constants.TestDynamicDataTypeProperty, (int)TestMethod.DataType);
testCase.SetPropertyValue(Constants.TestDynamicDataProperty, data);
testCase.SetPropertyValue(Constants.TestDataSourceIgnoreReasonProperty, TestMethod.TestDataSourceIgnoreReason);
}

SetTestCaseId(testCase, testFullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class TestResult
/// </summary>
public UnitTestOutcome Outcome { get; set; }

internal string? IgnoreReason { get; set; }

/// <summary>
/// Gets or sets the exception thrown when test is failed.
/// </summary>
Expand Down

0 comments on commit 1bae8e7

Please sign in to comment.