user384884
user384884

Reputation: 3

Xunit Skip Tests

can you tell me if it is possible to somehow skip test execution depending on the value of a Boolean variable in the json file, the skip attribute is not tied to the condition, and reflection does not see this attribute, just if-return does not suitable.

I need the test not to even run, so it doesn’t suit me if it simply returns successful execution (without executing the body)

Skip attribute, If-Return in body of test Reflection

Skip tests depending on the value of a boolean variable but it doesn't work

Upvotes: -1

Views: 1786

Answers (2)

user26881681
user26881681

Reputation: 1

This can now be done in XUnit.V3 with Assert.Skip() What's New in V3

Upvotes: 0

Peter Csala
Peter Csala

Reputation: 22829

As far as I know xUnit does not provide built-in solution for this currently. But there are 3rd party libraries like Xunit.SkippableFact which allows you to skip certain tests during runtime if some conditions met.

[SkippableFact]
public void Given_When_Then()
{
    Skip.If(EvaluateYourDynamicCondition(), "It is skipped based xyz.json");

    // Arrange
    // ...

}

SkippableTheory is also supported if you are using parameterized unit tests (PUT).


UPDATE #1

In case of xUnit V3, which is not released at the time of writing, will support dynamic skipability.

[Fact]
public void Given_When_Then()
{
    Assert.SkipWhen(EvaluateYourDynamicCondition(), "It is skipped based xyz.json");

    // Arrange
    // ...

}

UPDATE #2

This library does not work as I need, tests are still executed, they just throw exceptions

It does work for me.

skippeableFact

Upvotes: 0

Related Questions