title: NUnit cancel a test in SetUp
body: <p>We use NUnit for our automated tests and we have some criteria that must be met in order for a test to run. In particular, we are using Xamarin.UITest for mobile UITesting and we need to check if we are currently testing a platform that we want to test. Unfortunately, there is no way for us to do it using categories.</p>
  
  <p>The way we do it right now is to have a list of platforms we want to test. In the <code>[SetUp]</code> method we then check if the current platform is contained in that list and if not, we abort the test. Currently, we abort the test by letting it fail with <code>Assert.Fail()</code>. However, we would prefer to let the test exit silently, with no failiure and no success message, just as if it was never run. Is that even possible and if so, how can it be done?</p>
  
  <p>Here's the current code:</p>
  
  <pre><code>private IList&lt;Platform&gt; _desiredPlatforms;
  
  public IList&lt;Platform&gt; DesiredPlatforms
  {
      get
      {
          if (_desiredPlatforms == null)
          {
              // read from environment variable
          }
          return _desiredPlatforms;
      }
  }
  
  [SetUp]
  public void BeforeEachTest()
  {
     // Check if the current platform is desired
     if (!DesiredPlatforms.Contains(_platform))
     {
          Assert.Fail("Aborting the current test as the current platform " + _platform + " is not listed in the DesiredPlatforms-list");
     }
     _app = AppInitializer.Instance.StartApp(_platform, _appFile);
  }
  </code></pre>