title: How can I automatically skip certain JUnit tests based on a condition?
body: <p>I would like a simple way to assign a priority value to my JUnit tests such that I can say 'run only priority 1 tests', 'run priority 1, 2 and 3 tests' etc. I am aware that I could just include a line like <code>Assume.assumeTrue("Test skipped for priority " + priority, priority &lt;= 2);</code> at the start of each test (where <code>priority</code> is the highest value priority tests I want to run and <code>2</code> is the priority value of this particular test), however copy-pasting a line at the start of each test doesn't seem a very good solution.</p>
  
  <p>I have tried writing a solution using a simple annotation which is detected by the JUnit Rule I am using anyway:</p>
  
  <pre><code>public class Tests {
      @Rule
      public TestRules rules = new TestRules();
      @Test
      @Priority(2)
      public void test1() {
          // perform test
      }
  }
  
  public class TestRules extends TestWatcher {
      private int priority = 1; // this value is manually changed to set the priority of tests to run
      @Override
      protected void starting(Description desc) {
          Priority testCasePriority = desc.getAnnotation(Priority.class);
          Assume.assumeTrue("Test skipped for priotity " + priority, testCasePriority == null || testCasePriority.value() &lt;= priority);
      }
  }
  
  @Target(ElementType.METHOD)
  @Retention(RetentionPolicy.RUNTIME)
  public @interface Priority {
      public int value() default 0;
  }
  </code></pre>
  
  <p>While this appears to work (the correct tests are shown as skipped in the Eclipse JUnit view) the tests are still performed, i.e. any code in <code>test1()</code> is still run.</p>
  
  <p>Does anyone have any idea how I can get the <code>Assume</code> in my Rule to actually skip the test?</p>