question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using skip feature with XUnit InlineData attribute throws InvalidOperationException

See original GitHub issue

Description

Adding a Skip parameter to XUnit InlineData attribute is throwing the below error:

Message: System.InvalidOperationException : TestOutput is not provided. Ensure that scenario is executed from method with [Scenario] attribute, or ITestOutputHelper instance is provided to FeatureFixture constructor.

Example of Scenario:


public class AdditionFeature: FeatureFixture
{

[InlineData(1,2, 3, Skip = "Skip this scenario because its faulty.")]
[Scenario]
public async Task Scenario_test_one_plus_two(int firstNumber, int secondNumber, int expectedResult) 
=> await Runner.WithContext<TestContext>()
			.AddSteps(
				given => given.Two_numbers_are_inputted.(firstnumber, secondnumber))
			.AddAsyncSteps(
				when => when.The_two_numbers_are_added())
			.AddSteps(
				then => then.The_two_numbers_should_be_EXPECTEDRESULT(expectedResult))
			.RunAsync();
}

Progress

  • Feature is implemented,
  • Ensured backward-compatibility,
  • Ensured good debugging experience
  • Wiki page is updated

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Suremakercommented, May 22, 2019

Hello @krt-c ,

Thanks for reporting it. I have to take a look at the details and will come back to you. For the time being pese use [IgnoreScenario()] described here

0reactions
Suremakercommented, Oct 28, 2019

List of changes:

  • Updated LightBDD to support Skip property on ScenarioAttribute as well as InlineDataAttribute, allow the test to run but make it ignored as soon as executed with Runner, so that outcome is included in the reports
  • Added UseXUnitSkipBehaviorAttribute that could enforce default xunit behavior.

The tests no longer fail when [InlineData] is used with Skip property.

The feature has been tested in:

  • VS Test Explorer (VS 2019 16.3.1)
  • Resharper
  • dotnet test command

Assuming the following code:

[Scenario]
[InlineData(2)]
[InlineData(3)]
[InlineData(4, Skip = "Not running it!")]
public void Eating_N_cakes(int n)
{
    var myCakes = 3;
    Runner.RunScenario(
        _ => Given_I_have_N_cakes(myCakes),
        _ => When_I_eat_N_of_them(n),
        _ => Then_I_should_have_N_left(myCakes - n));
}

[Scenario(Skip = "It will just not happen!")]
public void Eating_lemons()
{
    Runner.RunScenario(
        _ => Given_I_have_a_lemon(),
        _ => When_I_eat_it(),
        _ => Then_I_should_have_none());
}

Before the change, the skipped tests were not present in the reports (and [InlineData] with Skip property were causing runtime issues): image

With the change, the skipped tests are included in the reports: image

Please note that even though the Scenario is marked as Ignored, the test method is effectively executed, especially any code up to Runner.RunScenario(). In case when this behavior is undesired, the native xunit treatment of skipped tests can be restored by adding [assembly: UseXUnitSkipBehavior] to the test project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Skip Fact/Theory when precondition is not satisfied
When the method lands in the catch it sets the Skip attribute and the test is skipped and shown as such in the...
Read more >
Skip ignored on xunit theory InlineData : RSRP-475671
When trying to skip a specific xunit test case by placing a Skip value on an InlineData attribute, the test is executed anyway....
Read more >
Unit Testing with C# and .NET (Full Guide) - Sergey Drozdov
xUnit provides options to facilitate this: Skipping tests: Use the Skip parameter on the [Fact] or [Theory] attributes to skip a test.
Read more >
Why did we build xUnit 1.0?
Sometimes, the excessive use of attributes can make you feel like you've diverged far from the underlying language. xUnit.net removed some attributes from...
Read more >
C# Quicktip: In Xunit how to skip a unit test from being run
When you have the ignore attribute above a testmethod the test will be skipped. For example: [TestMethod] [Ignore] public void ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found