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

Should FactAttribute support SkipWhen/SkipUnless properties? #2339

Open
bradwilson opened this issue Jun 30, 2021 · 4 comments
Open

Should FactAttribute support SkipWhen/SkipUnless properties? #2339

bradwilson opened this issue Jun 30, 2021 · 4 comments

Comments

@bradwilson
Copy link
Member

bradwilson commented Jun 30, 2021

Proposed usage would be something like:

public class MyTests
{
    public static bool IsMono => Type.GetType("Mono.Runtime") != null;

    [Fact(SkipWhen = nameof(IsMono))]
    public void TestThatFailsOnMono() { ... }

    [Fact(SkipUnless = nameof(IsMono))]
    public void TestThatRequiresMono() { ... }
}
@Romanx
Copy link

Romanx commented Jul 1, 2021

Since this is a discussion i'll add some thoughts

I can find a use for this if similar to test data we could point it at a property or method which would calculate the result. With that assumption it could clean duplicated SkipWhen/SkipUnless at the top of methods if you have a bunch which are skipped on the same condition e.g. OS conditions.

I'm assuming you could also wrap in your own fact that includes the SkipWhen/SkipUnless so it can be easier to find e.g. WindowsOnlyFact or whatever.

@bradwilson
Copy link
Member Author

Yeah, sorry, I started moving things around on the 3.0 work list and created this issue, but forgot to fill in the description. 😂

Yes, the idea would be that it would point to something which calculated whether to skip at discovery time, much like MemberData does today.

@molekp
Copy link

molekp commented Aug 30, 2021

I like this proposal, but it would me much usable when we can calculate it real time. Something like https://github.com/AArnott/Xunit.SkippableFact.

f. egz.

[Fact]
[InlineData(true)]
[InlineData(false)]
public void TestSkipping(bool shouldSkip)
{
       Assert.Skip(shouldSkip);//when true it breaks hiere with test result as Skipped

       Assert.False(shouldSkip);//when false it should Success
}

or something like that:

[Fact(SkipWhenExceptionType = typeof(SkipException)]
[InlineData(true)]
[InlineData(false)]
public void TestSkipping(bool shouldSkip)
{
       _ = !shouldSkip ?? throw new SkipException("Should skip this test")//when true it breaks hiere with test result as Skipped

       Assert.False(shouldSkip);//when false it should Success
}

@bradwilson
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants