View Javadoc
1   package org.junit.tests.running.classes;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.fail;
5   
6   import org.junit.Test;
7   import org.junit.runner.JUnitCore;
8   import org.junit.runner.Result;
9   import org.junit.runner.RunWith;
10  import org.junit.runners.Suite;
11  import org.junit.runners.model.InitializationError;
12  
13  public class UseSuiteAsASuperclassTest {
14  
15      public static class TestA {
16          @Test
17          public void pass() {
18          }
19      }
20  
21      public static class TestB {
22          @Test
23          public void dontPass() {
24              fail();
25          }
26      }
27  
28      public static class MySuite extends Suite {
29          public MySuite(Class<?> klass) throws InitializationError {
30              super(klass, new Class[]{TestA.class, TestB.class});
31          }
32      }
33  
34      @RunWith(MySuite.class)
35      public static class AllWithMySuite {
36      }
37  
38      @Test
39      public void ensureTestsAreRun() {
40          JUnitCore core = new JUnitCore();
41          Result result = core.run(AllWithMySuite.class);
42          assertEquals(2, result.getRunCount());
43          assertEquals(1, result.getFailureCount());
44      }
45  }