Skip to content

Commit

Permalink
Also report a test case skipped if it returnsearly
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbeuk committed Apr 26, 2021
1 parent 4aedcd8 commit 66820c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions samples/BasicSample/ScenarioWithSkippedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void Scenario1(ScenarioContext scenario)
Assert.True(true);
});

return;

#pragma warning disable CS0162 // Unreachable code detected
scenario.Fact("This test should never be reached and therefore always be skipped", () =>
{
Assert.True(true);
});
#pragma warning restore CS0162 // Unreachable code detected
}
}
}
11 changes: 11 additions & 0 deletions src/ScenarioTests/Internal/ScenarioFactTestCaseRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ protected override async Task<RunSummary> RunTestAsync()
var bufferedMessageBus = new BufferedMessageBus(MessageBus);
var stopwatch = Stopwatch.StartNew();
var skipAdditionalTests = false;
var testRecorded = false;
pendingRestart = false; // By default we dont expect a new restart

object? capturedArgument = null;
ScenarioContext scenarioContext = null;

scenarioContext = new ScenarioContext(scenarioFactTestCase.FactName, async (object? argument, Func<Task> invocation) =>
{
testRecorded = true;

if (skipAdditionalTests)
{
pendingRestart = true; // when we discovered more tests after a test completed, allow us to restart
Expand Down Expand Up @@ -117,6 +120,14 @@ protected override async Task<RunSummary> RunTestAsync()
RunSummary result;

result = await CreateTestRunner(test, bufferedMessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, SkipReason, BeforeAfterAttributes, Aggregator, CancellationTokenSource).RunAsync();

// We should have expected at least one test run. We probably returned before our target test was able to run
if (!testRecorded)
{
bufferedMessageBus.QueueMessage(new TestSkipped(test, scenarioContext.SkippedReason ?? "No applicable tests were able to run"));
result = new RunSummary { Skipped = 1, Total = 1 };
}

aggregatedResult.Aggregate(result);

stopwatch.Stop();
Expand Down

0 comments on commit 66820c7

Please sign in to comment.