Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.googlecode.junittoolbox;
 
 
Runs all inner test classes of the class annotated with @RunWith(InnerTestClassesSuite.class). In contrast to the org.junit.experimental.runners.Enclosed runner provided by JUnit, it detects if an inner class is actually a test class and ignores all other inner classes. Example:
     @RunWith(InnerTestClassesSuite.class)
     public class LoginBeanTests {

         public static class UnitTests {
             @Test
             public void test1() { ... }
         }

         @Configuration
         public static class IntegrationTestsConfig { ... }

         @RunWith(SpringJUnit4ClassRunner.class)
         @ContextConfiguration(classes = IntegrationTestsConfig.class)
         public static class IntegrationTests {
             @Test
             public void test2() { ... }
         }
     }
 
public class InnerTestClassesSuite extends Suite {
    private static List<RunnergetRunnersForInnerTestClasses(Class<?> klassRunnerBuilder runnerBuilderthrows InitializationError {
        Class<?>[] innerClasses = klass.getClasses();
        final List<Runnerrunners = new ArrayList<Runner>();
        for (Class<?> innerClass : innerClasses) {
            try {
                Runner runner = runnerBuilder.runnerForClass(innerClass);
                if (runner instanceof ErrorReportingRunner) {
                    // runnerBuilder.runnerForClass(innerClass) failed,
                    // inner class is not a test class and therefore ignored
                } else {
                    runners.add(runner);
                }
            } catch (Throwable ignored) {
                // runnerBuilder.runnerForClass(innerClass) failed,
                // inner class is not a test class and therefore ignored
            }
        }
        return runners;
    }
    public InnerTestClassesSuite(Class<?> klassRunnerBuilder runnerBuilderthrows InitializationError {
        super(klassgetRunnersForInnerTestClasses(klassrunnerBuilder));
    }
New to GrepCode? Check out our FAQ X