title: Conditionally run unit tests using SpringJUnit4ClassRunner at run time
body: <p>I have a jUnit test case to test spring managed beans of helpers, utility, services etc. So that I have set the unit test class with SpringJUnit4ClassRunner and contextConfiguration. e.g. -</p>
  <pre><code>@ContextConfiguration({ &quot;classpath:context-file.xml&quot; })
  @RunWith(SpringJUnit4ClassRunner.class)
  public class UnitTests {
  
  
   @Test
   public void test1() {
     //...
   }
  
   @Test
   public void test2() {
     //...
   }
  
   @Test
   public void test3() {
     //...
   }
  
   @Test
   public void test4() {
    //...
   }
  
  }
  </code></pre>
  <p>I want to run these four(or more) unit test on some condition at run time e.g.
  if internet is available then run test UnitTests.test1(), if database is connected then run UnitTests.test2(), if image files directory is present then run test UnitTests.test3(), if a remote server is responding properly then run test UnitTests.test4().</p>
  <p>Although I have went through jUnit <strong>org.junit.Assume</strong> but it doesn't suit, it can either enable the test framework to run all tests or skip all tests. <strong>@Ignore</strong> is also not applicable for these scenario. Also went through <strong>junit-ext</strong> (<a href="https://code.google.com/p/junit-ext/" rel="nofollow noreferrer">https://code.google.com/p/junit-ext/</a>), but its dependency is not available on maven-central repository (<a href="https://mvnrepository.com/artifact/com.googlecode.junit-ext/junit-ext/1.0-RC3" rel="nofollow noreferrer">junit-ext-maven-dependency</a>). Please anybody help me out with some peace of code here.</p>