Skip to content
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

Setting Option for marking not runnable tests as failed #524

Merged
merged 4 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal void SendTestResults(TestCase test, UnitTestResult[] unitTestResults, D
continue;
}

var testResult = unitTestResult.ToTestResult(test, startTime, endTime, MSTestSettings.CurrentSettings.MapInconclusiveToFailed);
var testResult = unitTestResult.ToTestResult(test, startTime, endTime, MSTestSettings.CurrentSettings.MapInconclusiveToFailed, MSTestSettings.CurrentSettings.MapNotRunnableToFailed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of passing individual values from settings : MapInconclusiveToFailed and MapNotRunnableToFailed, prefer passing the entire settings. In future, we can extract whichever value will be required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Passing entire adapter settings now. Modified the tests with these as well.


if (unitTestResult.DatarowIndex >= 0)
{
Expand Down
12 changes: 10 additions & 2 deletions src/Adapter/MSTest.CoreAdapter/Helpers/UnitTestOutcomeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ internal static class UnitTestOutcomeHelper
/// </summary>
/// <param name="unitTestOutcome"> The unit Test Outcome. </param>
/// <param name="mapInconclusiveToFailed">Should map inconclusive to failed.</param>
/// <param name="mapNotRunnableToFailed">Should map not runnable to failed</param>
/// <returns>The Test platforms outcome.</returns>
internal static TestOutcome ToTestOutcome(UnitTestOutcome unitTestOutcome, bool mapInconclusiveToFailed)
internal static TestOutcome ToTestOutcome(UnitTestOutcome unitTestOutcome, bool mapInconclusiveToFailed, bool mapNotRunnableToFailed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Pass entire settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Passing entire adapter settings now.

{
switch (unitTestOutcome)
{
Expand All @@ -29,7 +30,14 @@ internal static TestOutcome ToTestOutcome(UnitTestOutcome unitTestOutcome, bool
return TestOutcome.Failed;

case UnitTestOutcome.NotRunnable:
return TestOutcome.None;
{
if (mapNotRunnableToFailed)
{
return TestOutcome.Failed;
}

return TestOutcome.None;
}

case UnitTestOutcome.Ignored:
return TestOutcome.Skipped;
Expand Down
18 changes: 18 additions & 0 deletions src/Adapter/MSTest.CoreAdapter/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public MSTestSettings()
{
this.CaptureDebugTraces = true;
this.MapInconclusiveToFailed = false;
this.MapNotRunnableToFailed = false;
this.EnableBaseClassTestMethodsFromOtherAssemblies = true;
this.ForcedLegacyMode = false;
this.TestSettingsFile = null;
Expand Down Expand Up @@ -121,6 +122,11 @@ private set
/// </summary>
public bool MapInconclusiveToFailed { get; private set; }

/// <summary>
/// Gets a value indicating whether a not runnable result be mapped to failed test.
/// </summary>
public bool MapNotRunnableToFailed { get; private set; }

/// <summary>
/// Gets a value indicating whether to enable discovery of test methods from base classes in a different assembly from the inheriting test class.
/// </summary>
Expand Down Expand Up @@ -159,6 +165,7 @@ public static void PopulateSettings(MSTestSettings settings)
CurrentSettings.ForcedLegacyMode = settings.ForcedLegacyMode;
CurrentSettings.TestSettingsFile = settings.TestSettingsFile;
CurrentSettings.MapInconclusiveToFailed = settings.MapInconclusiveToFailed;
CurrentSettings.MapNotRunnableToFailed = settings.MapNotRunnableToFailed;
CurrentSettings.EnableBaseClassTestMethodsFromOtherAssemblies = settings.EnableBaseClassTestMethodsFromOtherAssemblies;
CurrentSettings.ParallelizationWorkers = settings.ParallelizationWorkers;
CurrentSettings.ParallelizationScope = settings.ParallelizationScope;
Expand Down Expand Up @@ -280,6 +287,7 @@ private static MSTestSettings ToSettings(XmlReader reader)
// <MSTestV2>
// <CaptureTraceOutput>true</CaptureTraceOutput>
// <MapInconclusiveToFailed>false</MapInconclusiveToFailed>
// <MapNotRunnableToFailed>false</MapNotRunnableToFailed>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

// <EnableBaseClassTestMethodsFromOtherAssemblies>false</EnableBaseClassTestMethodsFromOtherAssemblies>
// <TestTimeout>5000</TestTimeout>
// <Parallelize>
Expand Down Expand Up @@ -350,6 +358,16 @@ private static MSTestSettings ToSettings(XmlReader reader)
break;
}

case "MAPNOTRUNNABLETOFAILED":
{
if (bool.TryParse(reader.ReadInnerXml(), out result))
{
settings.MapNotRunnableToFailed = result;
}

break;
}

case "SETTINGSFILE":
{
string fileName = reader.ReadInnerXml();
Expand Down
5 changes: 3 additions & 2 deletions src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ internal UnitTestResult(UnitTestOutcome outcome, string errorMessage)
/// <param name="startTime"> The start Time. </param>
/// <param name="endTime"> The end Time. </param>
/// <param name="mapInconclusiveToFailed">Indication to map inconclusive tests to failed.</param>
/// <param name="mapNotRunnableToFailed">Indication to map not runnable to failed.</param>
/// <returns> The <see cref="TestResult"/>. </returns>
internal TestResult ToTestResult(TestCase testCase, DateTimeOffset startTime, DateTimeOffset endTime, bool mapInconclusiveToFailed)
internal TestResult ToTestResult(TestCase testCase, DateTimeOffset startTime, DateTimeOffset endTime, bool mapInconclusiveToFailed, bool mapNotRunnableToFailed)
{
Debug.Assert(testCase != null, "testCase");

Expand All @@ -159,7 +160,7 @@ internal TestResult ToTestResult(TestCase testCase, DateTimeOffset startTime, Da
Duration = this.Duration,
ErrorMessage = this.ErrorMessage,
ErrorStackTrace = this.ErrorStackTrace,
Outcome = UnitTestOutcomeHelper.ToTestOutcome(this.Outcome, mapInconclusiveToFailed),
Outcome = UnitTestOutcomeHelper.ToTestOutcome(this.Outcome, mapInconclusiveToFailed, mapNotRunnableToFailed),
StartTime = startTime,
EndTime = endTime
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void ToTestResultShouldReturnConvertedTestResultWithFieldsSet()
var endTime = DateTimeOffset.Now;

// Act
var testResult = result.ToTestResult(testCase, startTime, endTime, mapInconclusiveToFailed: false);
var testResult = result.ToTestResult(testCase, startTime, endTime, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);

// Validate
Assert.AreEqual(testCase, testResult.TestCase);
Expand All @@ -87,7 +87,7 @@ public void ToTestResultForUniTestResultWithStandardOutShouldReturnTestResultWit
StandardOut = "DummyOutput"
};
TestCase testCase = new TestCase("Foo", new Uri("Uri", UriKind.Relative), Assembly.GetExecutingAssembly().FullName);
var testresult = result.ToTestResult(testCase, DateTimeOffset.Now, DateTimeOffset.Now, mapInconclusiveToFailed: false);
var testresult = result.ToTestResult(testCase, DateTimeOffset.Now, DateTimeOffset.Now, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.IsTrue(testresult.Messages.All(m => m.Text.Contains("DummyOutput") && m.Category.Equals("StdOutMsgs")));
}

Expand All @@ -99,7 +99,7 @@ public void ToTestResultForUniTestResultWithDebugTraceShouldReturnTestResultWith
DebugTrace = "DummyDebugTrace"
};
TestCase testCase = new TestCase("Foo", new Uri("Uri", UriKind.Relative), Assembly.GetExecutingAssembly().FullName);
var testresult = result.ToTestResult(testCase, DateTimeOffset.Now, DateTimeOffset.Now, mapInconclusiveToFailed: false);
var testresult = result.ToTestResult(testCase, DateTimeOffset.Now, DateTimeOffset.Now, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.IsTrue(testresult.Messages.All(m => m.Text.Contains("\n\nDebug Trace:\nDummyDebugTrace") && m.Category.Equals("StdOutMsgs")));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,63 @@ public class UnitTestOutcomeHelperTests
[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomePassedShouldReturnTestOutcomePassed()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Passed, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Passed, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.Passed, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeFailedShouldReturnTestOutcomeFailed()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Failed, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Failed, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.Failed, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeErrorShouldReturnTestOutcomeFailed()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Error, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Error, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.Failed, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeNotRunnableShouldReturnTestOutcomeNone()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.NotRunnable, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.NotRunnable, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.None, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeTimeoutShouldReturnTestOutcomeFailed()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Timeout, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Timeout, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.Failed, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeIgnoredShouldReturnTestOutcomeSkipped()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Ignored, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Ignored, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.Skipped, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeInconclusiveShouldReturnTestOutcomeSkipped()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Inconclusive, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.Inconclusive, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.Skipped, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeNotFoundShouldReturnTestOutcomeNotFound()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.NotFound, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.NotFound, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.NotFound, resultOutcome);
}

[TestMethod]
public void UniTestHelperToTestOutcomeForUnitTestOutcomeInProgressShouldReturnTestOutcomeNone()
{
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.InProgress, mapInconclusiveToFailed: false);
var resultOutcome = UnitTestOutcomeHelper.ToTestOutcome(UnitTestOutcome.InProgress, mapInconclusiveToFailed: false, mapNotRunnableToFailed: false);
Assert.AreEqual(TestOutcome.None, resultOutcome);
}
}
Expand Down
Loading