Example usage for junit.framework TestSuite TestSuite

List of usage examples for junit.framework TestSuite TestSuite

Introduction

In this page you can find the example usage for junit.framework TestSuite TestSuite.

Prototype

TestSuite

Source Link

Usage

From source file:grails.util.RunTests.java

public static void main(String[] args) {
    int exitCode = 0;
    try {//from   ww w .j  a v  a  2 s . co m
        log.info("Bootstrapping Grails from classpath");
        ConfigurableApplicationContext appCtx = (ConfigurableApplicationContext) GrailsUtil
                .bootstrapGrailsFromClassPath();
        GrailsApplication application = (GrailsApplication) appCtx.getBean(GrailsApplication.APPLICATION_ID);

        Class[] allClasses = application.getAllClasses();
        log.debug("Going through [" + allClasses.length + "] classes");
        TestSuite s = new TestSuite();
        for (int i = 0; i < allClasses.length; i++) {
            Class clazz = allClasses[i];
            if (TestCase.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
                log.debug("Adding test [" + clazz.getName() + "]");
                s.addTest(new GrailsTestSuite(appCtx, clazz));
            } else {
                log.debug("[" + clazz.getName() + "] is not a test case.");
            }
        }
        String[] beanNames = appCtx.getBeanNamesForType(PersistenceContextInterceptor.class);
        PersistenceContextInterceptor interceptor = null;
        if (beanNames.length > 0) {
            interceptor = (PersistenceContextInterceptor) appCtx.getBean(beanNames[0]);
        }

        try {
            if (interceptor != null) {
                interceptor.init();
            }
            TestResult r = TestRunner.run(s);
            exitCode = r.errorCount() + r.failureCount();
            if (exitCode > 0) {
                System.err.println("Tests failed!");
            }
            if (interceptor != null)
                interceptor.flush();
        } finally {
            if (interceptor != null)
                interceptor.destroy();
        }
    } catch (Exception e) {
        log.error("Error executing tests: " + e.getMessage(), e);
        exitCode = 1;
    } finally {
        System.exit(exitCode);
    }
}

From source file:TestClassComposite.java

static public Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTestSuite(TestClassOne.class);

    suite.addTest(TestClassTwo.suite());
    return suite;
}

From source file:TestClassOne.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    // Only include short tests
    suite.addTest(new TestClassTwo("testShortTest"));
    suite.addTest(new TestClassTwo("testAnotherShortTest"));
    return suite;
}

From source file:MainClass.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    // Only include short tests
    suite.addTest(new MainClass("testShortTest"));
    suite.addTest(new MainClass("testAnotherShortTest"));

    TestSetup wrapper = new TestSetup(suite) {
        protected void setUp() {
            oneTimeSetUp();//from w  ww  .java2 s. com
        }

        protected void tearDown() {
            oneTimeTearDown();
        }
    };

    return wrapper;
}

From source file:TestSample.java

public static void run(Class which, String[] args) {
    TestSuite suite = null;//w ww.  java 2  s. c  o  m
    if (args.length != 0) {
        try {
            java.lang.reflect.Constructor ctor;
            ctor = which.getConstructor(new Class[] { String.class });
            suite = new TestSuite();
            for (int i = 0; i < args.length; i++) {
                suite.addTest((TestCase) ctor.newInstance(new Object[] { args[i] }));
            }
        } catch (Exception e) {
            System.err.println("Unable to instantiate " + which.getName() + ": " + e.getMessage());
            System.exit(1);
        }

    } else {
        try {
            Method suite_method = which.getMethod("suite", new Class[0]);
            suite = (TestSuite) suite_method.invoke(null, null);
        } catch (Exception e) {
            suite = new TestSuite(which);
        }
    }
    junit.textui.TestRunner.run(suite);
}

From source file:TestClassComposite.java

public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(new TestClassTwo("testLongRunner"));

    return suite;
}

From source file:TestClassOne.java

static public Test suite() {
    TestSuite suite = new TestSuite();
    // Grab everything:
    suite.addTestSuite(TestClassOne.class);
    // Use the suite method:
    suite.addTest(TestClassTwo.suite());
    return suite;
}

From source file:com.networknt.light.util.UtilTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(UtilTest.class);
    return suite;
}

From source file:com.networknt.light.server.DbServiceTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(DbServiceTest.class);
    return suite;
}

From source file:com.networknt.light.rule.access.AccessRuleTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(AccessRuleTest.class);
    return suite;
}