0

I am new to automation and working with a framework where they have rename/customized the Fact and Theory attributes for the xunit test. Well they only Pass fail and I wanted to run Warning too. So I came across "Skip.If()" with the xunit.SkippableFact nuget package. This requires me to add the attribute [SkippableFact] or [SkippableTheory] to the unit test in order for the warning to display with "skip.if()". If I do not and just add the standard [Fact] [Theory] it displays a red fail which I do not want. These are just smoke test so I am ok with the warning if the test was not able to run. See my prior post on why I wanted to use xunit.SkippableFact.

Stopping a test in C# visual studio if no data exist with smoke test

So my problem is that I want to be able to use the rename/customized Fact/Theory attribute to know to use [SkippableFact] or just a plain [Fact] based on a TraitAttribute or something. I have tried redoing the constructor and looking into the XunitTestCaseDiscoverer but with no success with my limited knowledge.

The 1st example is how we utilized Fact rename and customized, which throws a failed test if the skip.if is wrong. The 2nd is the standard xunit naming that does the same as the 1st and throws a fail too. The 3rd gives me what I want,which is a warning but I want to somehow incorporate [SkippableFact] into the first since you can not have multiple Fact/Theory attributes.

Thanks in advance.

    [UI, Scenario("Example"), Tags(TestScope.Smoke,TestScope.Skippable, Priority.One)]
    [Evaluate("Example")]
    public async Task ExampleTest()
    {
      skip.if(Data=0,"No Data to run smoke test"//This throws failed result 
      //for test
    }

    [Fact]
    public async Task ExampleTest()
    {
      skip.if(Data=0,"No Data to run smoke test"//This throws failed result 
      //for test
    }

    [SkippableFact]
    public async Task ExampleTest()
    {
       skip.if(Data=0,"No Data to run smoke test"//This throws warning 
       //result for test which is what I want
    }
rowdog_14
  • 31
  • 7

1 Answers1

1

Hey here's what I did:

public class MultiFact : FactAttribute
{
    public MultiFact(params Type[] types)
    {
        var result = types.Select(Activator.CreateInstance).Cast<FactAttribute>().ToList();

        if (result.Any(it => Text.IsNotBlank(it.Skip)))
        {
            Skip = string.Join(", ", result.Where(it => Text.IsNotBlank(it.Skip)).Select(it => it.Skip));
        }
    }
}

with usage like:

[MultiFact(typeof(OnlyWhenSomeServiceAvailable), typeof(GuiCheck))]

where OnlyWhenSomeServiceAvailable and GuiCheck also inherit from FactAttribute.

bit clunky but it's alright