Skip to content

Commit 91f9f4f

Browse files
jessehouwingAbhitejJohn
authored andcommitted
Improve handling of Assert.Inconclusive (#277)
* Improve handling of Assert.Inconclusive * Improved namign in new unit tests for Assert.Inconclusive.
1 parent fa2fa84 commit 91f9f4f

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

src/Adapter/MSTest.CoreAdapter/Execution/TestMethodInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private TestResult ExecuteInternal(object[] arguments)
231231

232232
if (result.Outcome != TestTools.UnitTesting.UnitTestOutcome.Passed)
233233
{
234-
if (ex.InnerException != null && ex.InnerException is AssertInconclusiveException)
234+
if (ex is UTF.AssertInconclusiveException || ex.InnerException is UTF.AssertInconclusiveException)
235235
{
236236
result.Outcome = TestTools.UnitTesting.UnitTestOutcome.Inconclusive;
237237
}
@@ -317,7 +317,7 @@ private bool IsExpectedException(Exception ex, TestResult result)
317317
// attribute's Verify method) is an AssertInconclusiveException. If so, set
318318
// the test outcome to Inconclusive.
319319
result.TestFailureException = new TestFailedException(
320-
exceptionFromVerify is AssertInconclusiveException ? UnitTestOutcome.Inconclusive : UnitTestOutcome.Failed,
320+
exceptionFromVerify is UTF.AssertInconclusiveException ? UnitTestOutcome.Inconclusive : UnitTestOutcome.Failed,
321321
exceptionFromVerify.TryGetMessage(),
322322
realException.TryGetStackTraceInformation());
323323
return false;

test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestMethodInfoTests.cs

+64
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,70 @@ public void TestMethodInfoInvokeShouldWaitForAsyncTestMethodsToComplete()
130130
Assert.AreEqual(UTF.UnitTestOutcome.Passed, result.Outcome);
131131
}
132132

133+
[TestMethodV1]
134+
public void TestMethodInfoInvokeAsyncShouldHandleThrowAssertInconclusive()
135+
{
136+
DummyTestClass.DummyAsyncTestMethodBody = () => Task.Run(() => { throw new UTF.AssertInconclusiveException(); });
137+
var asyncMethodInfo = typeof(DummyTestClass).GetMethod("DummyAsyncTestMethod");
138+
139+
var method = new TestMethodInfo(
140+
asyncMethodInfo,
141+
this.testClassInfo,
142+
this.testMethodOptions);
143+
144+
var result = method.Invoke(null);
145+
146+
Assert.AreEqual(UTF.UnitTestOutcome.Inconclusive, result.Outcome);
147+
}
148+
149+
[TestMethodV1]
150+
public void TestMethodInfoInvokeAsyncShouldHandleAssertInconclusive()
151+
{
152+
DummyTestClass.DummyAsyncTestMethodBody = () => Task.Run(() => { UTF.Assert.Inconclusive(); });
153+
var asyncMethodInfo = typeof(DummyTestClass).GetMethod("DummyAsyncTestMethod");
154+
155+
var method = new TestMethodInfo(
156+
asyncMethodInfo,
157+
this.testClassInfo,
158+
this.testMethodOptions);
159+
160+
var result = method.Invoke(null);
161+
162+
Assert.AreEqual(UTF.UnitTestOutcome.Inconclusive, result.Outcome);
163+
}
164+
165+
[TestMethodV1]
166+
public void TestMethodInfoInvokeShouldHandleThrowAssertInconclusive()
167+
{
168+
DummyTestClass.TestMethodBody = (d) => { throw new UTF.AssertInconclusiveException(); };
169+
var dummyMethodInfo = typeof(DummyTestClass).GetMethod("DummyTestMethod");
170+
171+
var method = new TestMethodInfo(
172+
dummyMethodInfo,
173+
this.testClassInfo,
174+
this.testMethodOptions);
175+
176+
var result = method.Invoke(null);
177+
178+
Assert.AreEqual(UTF.UnitTestOutcome.Inconclusive, result.Outcome);
179+
}
180+
181+
[TestMethodV1]
182+
public void TestMethodInfoInvokeShouldHandleAssertInconclusive()
183+
{
184+
DummyTestClass.TestMethodBody = (d) => { UTF.Assert.Inconclusive(); };
185+
var dummyMethodInfo = typeof(DummyTestClass).GetMethod("DummyTestMethod");
186+
187+
var method = new TestMethodInfo(
188+
dummyMethodInfo,
189+
this.testClassInfo,
190+
this.testMethodOptions);
191+
192+
var result = method.Invoke(null);
193+
194+
Assert.AreEqual(UTF.UnitTestOutcome.Inconclusive, result.Outcome);
195+
}
196+
133197
[TestMethodV1]
134198
public void TestMethodInfoInvokeShouldListenForDebugAndTraceLogsWhenEnabled()
135199
{

0 commit comments

Comments
 (0)