Skip to content

Commit

Permalink
[Refactor] Simplify FixtureTestResult (#4723)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 authored Jan 20, 2025
1 parent 8cec650 commit 1746ecc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private async Task ExecuteTestsWithTestRunnerAsync(
{
var result = new TestTools.UnitTesting.TestResult()
{
Outcome = fixtureTestResult.Outcome.ToAdapterOutcome(),
Outcome = fixtureTestResult.Outcome,
};
SendTestResults(currentTest, [result], DateTimeOffset.Now, DateTimeOffset.Now, testExecutionRecorder);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using UnitTestOutcome = Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel.UnitTestOutcome;
using UnitTestOutcome = Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
Expand Down Expand Up @@ -93,31 +93,31 @@ internal FixtureTestResult GetFixtureTestResult(TestMethod testMethod, string fi
if (fixtureType == Constants.ClassInitializeFixtureTrait)
{
return testMethodInfo.Parent.IsClassInitializeExecuted
? new(true, GetOutcome(testMethodInfo.Parent.ClassInitializationException), testMethodInfo.Parent.ClassInitializationException?.Message)
: new(true, UnitTestOutcome.Inconclusive, null);
? new(true, GetOutcome(testMethodInfo.Parent.ClassInitializationException))
: new(true, UnitTestOutcome.Inconclusive);
}

if (fixtureType == Constants.ClassCleanupFixtureTrait)
{
return testMethodInfo.Parent.IsClassInitializeExecuted
? new(testMethodInfo.Parent.IsClassInitializeExecuted, GetOutcome(testMethodInfo.Parent.ClassCleanupException), testMethodInfo.Parent.ClassCleanupException?.Message)
: new(true, UnitTestOutcome.Inconclusive, null);
? new(true, GetOutcome(testMethodInfo.Parent.ClassCleanupException))
: new(true, UnitTestOutcome.Inconclusive);
}
}

if (_fixtureTests.TryGetValue(testMethod.AssemblyName, out testMethodInfo))
{
if (fixtureType == Constants.AssemblyInitializeFixtureTrait)
{
return new(true, GetOutcome(testMethodInfo.Parent.Parent.AssemblyInitializationException), testMethodInfo.Parent.Parent.AssemblyInitializationException?.Message);
return new(true, GetOutcome(testMethodInfo.Parent.Parent.AssemblyInitializationException));
}
else if (fixtureType == Constants.AssemblyCleanupFixtureTrait)
{
return new(true, GetOutcome(testMethodInfo.Parent.Parent.AssemblyCleanupException), testMethodInfo.Parent.Parent.AssemblyInitializationException?.Message);
return new(true, GetOutcome(testMethodInfo.Parent.Parent.AssemblyCleanupException));
}
}

return new(false, UnitTestOutcome.Inconclusive, null);
return new(false, UnitTestOutcome.Inconclusive);

// Local functions
static UnitTestOutcome GetOutcome(Exception? exception) => exception == null ? UnitTestOutcome.Passed : UnitTestOutcome.Failed;
Expand Down Expand Up @@ -259,7 +259,7 @@ private static TestResult RunAssemblyInitializeIfNeeded(TestMethodInfo testMetho
}
catch (Exception ex)
{
var testFailureException = new TestFailedException(UTF.UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation());
var testFailureException = new TestFailedException(UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation());
result = new TestResult() { TestFailureException = testFailureException };
}
finally
Expand Down
14 changes: 5 additions & 9 deletions src/Adapter/MSTest.TestAdapter/ObjectModel/FixtureTestResult.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

[Serializable]
internal sealed class FixtureTestResult
internal readonly struct FixtureTestResult
{
internal FixtureTestResult(bool isExecuted, UnitTestOutcome outcome, string? exceptionMessage)
internal FixtureTestResult(bool isExecuted, UTF.UnitTestOutcome outcome)
{
IsExecuted = isExecuted;
Outcome = outcome;
ExceptionMessage = exceptionMessage;
}

/// <summary>
Expand All @@ -21,10 +22,5 @@ internal FixtureTestResult(bool isExecuted, UnitTestOutcome outcome, string? exc
/// <summary>
/// Gets the outcome of the test.
/// </summary>
public UnitTestOutcome Outcome { get; }

/// <summary>
/// Gets the exception message if any.
/// </summary>
public string? ExceptionMessage { get; }
public UTF.UnitTestOutcome Outcome { get; }
}

0 comments on commit 1746ecc

Please sign in to comment.