Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Support multiple conditions in [ConditionalFact] and [ConditionalTheory]#619

Merged
roncain merged 2 commits intodotnet:masterfrom
roncain:multiple-conditions-in-conditionalfact
Apr 8, 2016
Merged

Support multiple conditions in [ConditionalFact] and [ConditionalTheory]#619
roncain merged 2 commits intodotnet:masterfrom
roncain:multiple-conditions-in-conditionalfact

Conversation

@roncain
Copy link

@roncain roncain commented Apr 7, 2016

Modifies [ConditionalFact] and [ConditionalTheory] attributes to accept
a variable number of condition member names.

Modifies ConditionalFactDiscoverer and ConditionalTheoryDiscoverer to
evaluate all of the conditions in the attributes. Conditions are
logically "and'ed", so any condition returning false marks the test
to be skipped.

Existing tests using [ConditionalFact] or [ConditionalTheory] do not
need to be modified. The only behavioral change is the phrasing of
the skip message which now begins "Conditions not met:..."

Fixes #610

Modifies [ConditionalFact] and [ConditionalTheory] attributes to accept
a variable number of condition member names.

Modifies ConditionalFactDiscoverer and ConditionalTheoryDiscoverer to
evaluate all of the conditions in the attributes.  Conditions are
logically "and'ed", so any condition returning false marks the test
to be skipped.

Existing tests using [ConditionalFact] or [ConditionalTheory] do not
need to be modified.  The only behavioral change is the phrasing of
the skip message which now begins "Conditions not met:..."

Fixes dotnet#610
@dnfclas
Copy link

dnfclas commented Apr 7, 2016

Hi @roncain, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@roncain
Copy link
Author

roncain commented Apr 7, 2016

Reviewers: this was tested by manually creating the following tests:

   [ConditionalFact()]
    public static void Test_No_Conditions()
    {
        Assert.True(true);
    }

    [ConditionalFact(nameof(Running_Elevated))]
    public static void Test_One_False_Conditions()
    {
        Assert.True(false);
    }

    [ConditionalFact(nameof(Certificates_Installed))]
    public static void Test_One_True_Condition()
    {
        Assert.True(true);
    }

    [ConditionalFact(nameof(Running_Elevated), nameof(Domain_Joined), nameof(Certificates_Installed))]
    public static void Test_Multiple_False_Conditions()
    {
        Assert.True(false);
    }

    [ConditionalFact(nameof(Built_On_Friday), nameof(Certificates_Installed))]
    public static void Test_Multiple_True_Conditions()
    {
        Assert.True(true);
    }

    [ConditionalTheory()]
    [InlineData("testdata")]
    public static void Test_No_Theory_Conditions(string theoryInput)
    {
        Assert.True(true);
    }

    [ConditionalTheory(nameof(Running_Elevated))]
    [InlineData("testdata")]
    public static void Test_One_False_Theory_Conditions(string theoryInput)
    {
        Assert.True(false);
    }

    [ConditionalTheory(nameof(Certificates_Installed))]
    [InlineData("testdata")]
    public static void Test_One_True_Theory_Condition(string theoryInput)
    {
        Assert.True(true);
    }

    [ConditionalTheory(nameof(Running_Elevated), nameof(Domain_Joined), nameof(Certificates_Installed))]
    [InlineData("testdata")]
    public static void Test_Multiple_False_Theory_Conditions(string theoryInput)
    {
        Assert.True(false);
    }

    [ConditionalTheory(nameof(Built_On_Friday), nameof(Certificates_Installed))]
    [InlineData("testdata")]
    public static void Test_Multiple_True_Theory_Conditions(string theoryInput)
    {
        Assert.True(true);
    }

The result of running these tests looks like this:

Discovering: System.ServiceModel.Primitives.Tests
Discovered:  System.ServiceModel.Primitives.Tests
Starting:    System.ServiceModel.Primitives.Tests
   ChannelFactoryTest.Test_One_False_Conditions [SKIP]
      Condition(s) not met: "Running_Elevated"
   ChannelFactoryTest.Test_Multiple_False_Theory_Conditions [SKIP]
      Condition(s) not met: "Running_Elevated", "Domain_Joined"
   ChannelFactoryTest.Test_One_False_Theory_Conditions [SKIP]
      Condition(s) not met: "Running_Elevated"
   ChannelFactoryTest.Test_Multiple_False_Conditions [SKIP]
      Condition(s) not met: "Running_Elevated", "Domain_Joined"
Finished:    System.ServiceModel.Primitives.Tests

=== TEST EXECUTION SUMMARY ===
   System.ServiceModel.Primitives.Tests  Total: 89, Errors: 0, Failed: 0, Skipped: 4, Time: 40.544s

/cc @stephentoub @iamjasonp @Priya91

@stephentoub
Copy link
Member

LGTM. Thanks.

@roncain
Copy link
Author

roncain commented Apr 7, 2016

Thanks @stephentoub . Is it okay for me to merge or would you like others eyes on this? I am considering your option 3 (special exception throw for custom skip messages) for a future enhancement to these discoverers, but not as part of this PR.

@stephentoub
Copy link
Member

@Priya91, could you take a look as well?

List<string> falseConditions = new List<string>();

if (symbols.Length == 2)
foreach (string entry in conditionMemberNames)

This comment was marked as spam.

This comment was marked as spam.

@bartonjs
Copy link
Member

bartonjs commented Apr 7, 2016

I'm all done being nitpicky. Thanks, Ron :).

@roncain
Copy link
Author

roncain commented Apr 7, 2016

I'm waiting for feedback from @Priya91 or @iamjasonp and will merge when I hear back. Alternatively, anyone else can feel free to merge at any time. Feedback from @bartonjs was incorporated into the 2nd commit.

string[] symbols = conditionMemberName.Split('.');
Type declaringType = testMethodDeclaringType;

if (symbols.Length == 2)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@iamjasonp
Copy link
Member

Nice 😄 LGTM

@roncain roncain merged commit 4990527 into dotnet:master Apr 8, 2016
@roncain roncain deleted the multiple-conditions-in-conditionalfact branch April 8, 2016 11:17
@Priya91
Copy link

Priya91 commented Apr 8, 2016

I was OOF yesterday, and saw this only now. LGTM! :)

roncain added a commit to roncain/wcf that referenced this pull request Apr 13, 2016
This update allows us to use multiple conditions in
[ConditionalFact] tests.

This feature was added to xunit.netcore.extensions with
PR dotnet/buildtools#619, and now
that the latest package is available, we can use it.
roncain added a commit to roncain/wcf that referenced this pull request Apr 13, 2016
This update allows us to use multiple conditions in
[ConditionalFact] tests.

This feature was added to xunit.netcore.extensions with
PR dotnet/buildtools#619, and now
that the latest package is available, we can use it.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants