Remembering Thoughts
  Twitter GitHub RSS

XUnit Ignore test at runtime (with SpecFlow tag @IgnoreLocally)

Code –>

NuGet –>

As Xunit has no Assert.Ignore() using the OptionallyIgnoreTestFactAttribute attribute on a method and setting McKeltCustom.SpecflowPlugin.Settings.IgnoreLocally == true will ignore the test at runtime

In SpecFlow set this as a plugin and use the tag @IgnoreLocally– before each test scenario is run turn on/off the setting to run this test.

Sample usage:

namespace Tester
    public class Dummy
        public Dummy()
            McKeltCustom.SpecflowPlugin.Settings.IgnoreLocally = true;
    public class TestFixture : IUseFixture<Dummy>
        public void DoesThisWork()
            Assert.True(false, "This should not be run");

        public void SetFixture(Dummy data)
            throw new NotImplementedException();

SpecFlow tag can be on a feature or a scenario


Add the following to the .config file

<!--<unitTestProvider name="xUnit" />-->
<generator allowDebugGeneratedFiles="false" allowRowTests="true" generateAsyncTests="false" path=".\lib"/>
<runtime stopAtFirstError="false" missingOrPendingStepsOutcome="Ignore">
    <register name="CustomGeneratorPlugin" type="PhoenixCustom.Generator.SpecflowPlugin.CustomGeneratorPlugin, PhoenixCustom.Generator.SpecflowPlugin" as="PhoenixCustom.Generator.SpecflowPlugin.CustomGeneratorPlugin, PhoenixCustom.Generator.SpecflowPlugin" />
    <register name="CustomGeneratorProvider" type="PhoenixCustom.Generator.SpecflowPlugin.CustomGeneratorProvider, PhoenixCustom.Generator.SpecflowPlugin" as="PhoenixCustom.Generator.SpecflowPlugin.CustomGeneratorProvider, PhoenixCustom.Generator.SpecflowPlugin" />
<trace traceSuccessfulSteps="true" traceTimings="false" minTracedDuration="0:0:0.1" stepDefinitionSkeletonStyle="RegexAttribute"/>
  <add name="McKeltCustom" path=".\lib" type="GeneratorAndRuntime"/>
<!-- For additional details on SpecFlow configuration options see -->
  <!-- This attribute is required in order to use StepArgument Transformation as described here;  -->
  <!-- This attribute is required in order to use StepArgument Transformation as described here;  -->
  <stepAssembly assembly="SpecFlow.Assist.Dynamic"/>
</specFlow> ```
Finally put the all compiled assemblies into a **_lib_** folder in the root folder of your SpecFlow project  


Tests marked with @IgnoreLocally  or OptionallyIgnoreTest will now skip the test if McKeltCustom.SpecflowPlugin.Settings.IgnoreLocally = true



Share on Twitter