Example usage for junit.framework TestSuite countTestCases

List of usage examples for junit.framework TestSuite countTestCases

Introduction

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

Prototype

public int countTestCases() 

Source Link

Document

Stub only

Usage

From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java

public static TestSuite suite(Class<? extends BrowserFunctionalTestCase> testcase) throws Exception {
    TestSuite suite = new TestSuite(testcase.getName());
    for (Method method : testcase.getMethods()) {
        if (method.getName().startsWith("test") && method.getParameterTypes().length == 0
                && method.getReturnType().equals(Void.TYPE)) {
            addTests(testcase, suite, method);
        }/*  w  w w.  j a  va  2  s.  c o m*/
    }
    if (suite.countTestCases() == 0) {
        suite.addTest(TestSuite.warning(testcase.getName() + " has no public test methods"));
    }
    return suite;
}

From source file:org.apache.jorphan.test.AllTests.java

/**
 * Starts a run through all unit tests found in the specified classpaths.
 * The first argument should be a list of paths to search. The second
 * argument is optional and specifies a properties file used to initialize
 * logging. The third argument is also optional, and specifies a class that
 * implements the UnitTestManager interface. This provides a means of
 * initializing your application with a configuration file prior to the
 * start of any unit tests./*w  ww.  j  av  a2 s .  c o  m*/
 * 
 * @param args
 *            the command line arguments
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("You must specify a comma-delimited list of paths to search " + "for unit tests");
        return;
    }
    String home = new File(System.getProperty("user.dir")).getParent();
    System.out.println("Setting JMeterHome: " + home);
    JMeterUtils.setJMeterHome(home);
    initializeLogging(args);
    initializeManager(args);

    String version = "JMeterVersion=" + JMeterUtils.getJMeterVersion();
    log.info(version);
    System.out.println(version);
    logprop("java.version", true);
    logprop("java.vm.name");
    logprop("java.vendor");
    logprop("java.home", true);
    logprop("file.encoding", true);
    // Display actual encoding used (will differ if file.encoding is not recognised)
    String msg = "default encoding=" + Charset.defaultCharset();
    System.out.println(msg);
    log.info(msg);
    logprop("user.home");
    logprop("user.dir", true);
    logprop("user.language");
    logprop("user.region");
    logprop("user.country");
    logprop("user.variant");
    final String showLocale = "Locale=" + Locale.getDefault().toString();
    log.info(showLocale);
    System.out.println(showLocale);
    logprop("os.name", true);
    logprop("os.version", true);
    logprop("os.arch");
    logprop("java.class.version");
    // logprop("java.class.path");
    String cp = System.getProperty("java.class.path");
    String cpe[] = JOrphanUtils.split(cp, java.io.File.pathSeparator);
    StringBuilder sb = new StringBuilder(3000);
    sb.append("java.class.path=");
    for (int i = 0; i < cpe.length; i++) {
        sb.append("\n");
        sb.append(cpe[i]);
        if (new java.io.File(cpe[i]).exists()) {
            sb.append(" - OK");
        } else {
            sb.append(" - ??");
        }
    }
    log.info(sb.toString());

    // ++
    // GUI tests throw the error
    // testArgumentCreation(org.apache.jmeter.config.gui.ArgumentsPanel$Test)java.lang.NoClassDefFoundError
    // at java.lang.Class.forName0(Native Method)
    // at java.lang.Class.forName(Class.java:141)
    // at
    // java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
    //
    // Try to find out why this is ...

    System.out.println("+++++++++++");
    logprop("java.awt.headless", true);
    logprop("java.awt.graphicsenv", true);
    //
    // try {//
    // Class c = Class.forName(n);
    // System.out.println("Found class: "+n);
    // // c.newInstance();
    // // System.out.println("Instantiated: "+n);
    // } catch (Exception e1) {
    // System.out.println("Error finding class "+n+" "+e1);
    // } catch (java.lang.InternalError e1){
    // System.out.println("Error finding class "+n+" "+e1);
    // }
    //
    System.out.println("------------");
    // don't call isHeadless() here, as it has a side effect.
    // --
    System.out.println("Creating test suite");
    TestSuite suite = suite(args[0]);
    int countTestCases = suite.countTestCases();
    System.out.println("Starting test run, test count = " + countTestCases);
    //        for (int i=0;i<suite.testCount();i++){
    //           Test testAt = suite.testAt(i);
    //           int testCases = testAt.countTestCases();
    //           if (testAt instanceof junit.framework.TestCase){
    //                System.out.print(((junit.framework.TestCase) testAt).getName());
    //            }
    //            if (testAt instanceof TestSuite){
    //                TestSuite testSuite = ((TestSuite) testAt);
    //                String name = testSuite.getName();
    //                System.out.print(name);
    //                System.out.println(" "+testCases);
    //            }                
    //        }

    // Jeremy Arnold: This method used to attempt to write results to
    // a file, but it had a bug and instead just wrote to System.out.
    // Since nobody has complained about this behavior, I'm changing
    // the code to not attempt to write to a file, so it will continue
    // behaving as it did before. It would be simple to make it write
    // to a file instead if that is the desired behavior.
    TestResult result = TestRunner.run(suite);
    // ++
    // Recheck settings:
    //System.out.println("+++++++++++");
    // System.out.println(e+"="+System.getProperty(e));
    // System.out.println(g+"="+System.getProperty(g));
    // System.out.println("Headless?
    // "+java.awt.GraphicsEnvironment.isHeadless());
    // try {
    // Class c = Class.forName(n);
    // System.out.println("Found class: "+n);
    // c.newInstance();
    // System.out.println("Instantiated: "+n);
    // } catch (Exception e1) {
    // System.out.println("Error with class "+n+" "+e1);
    // } catch (java.lang.InternalError e1){
    // System.out.println("Error with class "+n+" "+e1);
    // }
    //System.out.println("------------");
    // --
    System.exit(result.wasSuccessful() ? 0 : 1); // this is needed because the test may start the AWT EventQueue thread which is not a daemon.
}

From source file:org.jetbrains.jet.plugin.quickfix.JetQuickFixTest.java

public static Test suite() {
    //setFilter(); //to launch only part of tests
    TestSuite suite = new TestSuite();

    FilenameFilter singleFileNameFilter = new FilenameFilter() {
        @Override/*from w  w w.  j  a v  a 2 s.c o m*/
        public boolean accept(File file, String s) {
            return s.startsWith("before") && !JetPsiCheckerMultifileTest.isMultiFileName(s);
        }
    };

    JetTestCaseBuilder.NamedTestFactory singleFileNamedTestFactory = new JetTestCaseBuilder.NamedTestFactory() {
        @NotNull
        @Override
        public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) {
            return new JetQuickFixTest(dataPath, name);
        }
    };

    File dir = new File(getTestDataPathBase());
    List<String> subDirs = Arrays
            .asList(quickFixTestsFilter != null ? dir.list(quickFixTestsFilter) : dir.list());
    Collections.sort(subDirs);
    for (String subDirName : subDirs) {
        final TestSuite singleFileTestSuite = JetTestCaseBuilder.suiteForDirectory(getTestDataPathBase(),
                subDirName, true, singleFileNameFilter, singleFileNamedTestFactory);
        if (singleFileTestSuite.countTestCases() != 0) {
            suite.addTest(singleFileTestSuite);
        }
    }
    return suite;
}