0

I have tests written using selenium and Xunit. I run them in the Azure release pipeline. I have 500+ tests, I want to make a condition if the login test fails then it won't execute other tests. How to do this in Azure DevOps or in Xunit?

  • You could store the login test result in a boolean somewhere and extend `FactAttribute` to skip based on that value. Check out [this answer](https://stackoverflow.com/a/4421941/3005230) for an example. – Travieso Jul 06 '21 at 18:01

1 Answers1

0

Thank you Travieso. Posting your suggestions as an answer to help other community members.

Below are the different options which helps in stop running different test

Most intrusive, compile time platform detection

Use MONOWIN command as a precompiler flag in VS Solution. which will define an attribute and ignores the test when compiled

public class IgnoreOnMonoFactAttribute : FactAttribute {
#if MONOWIN
    public IgnoreOnMonoFactAttribute() {
        Skip = "Ignored on Mono";
    }
#endif
}

somewhat intrusive - runtime platform detection

Here is a similar solution to option1, except no separate configuration is required:

public class IgnoreOnMonoFactAttribute : FactAttribute {

    public IgnoreOnMonoFactAttribute() {
        if(IsRunningOnMono()) {
            Skip = "Ignored on Mono";
        }
    }
    /// <summary>
    /// Determine if runtime is Mono.
    /// Taken from http://stackoverflow.com/questions/721161
    /// </summary>
    /// <returns>True if being executed in Mono, false otherwise.</returns>
    public static bool IsRunningOnMono() {
        return Type.GetType("Mono.Runtime") != null;
    }
}

  • The tests what ever you are performing in xunit, the [Fact] should be replaced with [IgnoreOnMonoFact]
  • CodeRush test runner still ran the [IgnoreOnMonoFact] test, but it did ignore the [Fact(Skip="reason")] test. I assume it is due to CodeRush reflecting xUnit and not actually running it with the aid of xUnit libraries. This works fine with xUnit runner.

For complete details check the SO.

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15