Example usage for junit.framework TestResult wasSuccessful

List of usage examples for junit.framework TestResult wasSuccessful

Introduction

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

Prototype

public synchronized boolean wasSuccessful() 

Source Link

Document

Returns whether the entire test was successful or not.

Usage

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./*  ww w  . j a  v  a  2 s. co 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.fhcrc.cpl.toolbox.filehandler.TabLoader.java

public static void main(String[] args) throws Exception {
    try {/*ww w  .ja v  a  2 s  . co  m*/
        Class c = Class.forName("org.fhcrc.cpas.data.ConvertHelper");
        c.getMethod("registerHelpers").invoke(null);

        Test test = TabLoaderTestCase.suite();
        TestResult result = new TestResult();
        test.run(result);
        System.out.println(result.wasSuccessful() ? "success" : "fail");

        Enumeration failures = result.failures();
        Throwable first = null;
        while (failures.hasMoreElements()) {
            TestFailure failure = (TestFailure) failures.nextElement();
            System.err.println(failure.toString());
            if (first == null)
                first = failure.thrownException();
        }
        Enumeration errors = result.errors();
        while (errors.hasMoreElements()) {
            TestFailure error = (TestFailure) errors.nextElement();
            System.err.println(error.toString());
            if (first == null)
                first = error.thrownException();
        }
        if (first != null) {
            System.err.println("first exception");
            first.printStackTrace(System.err);
        }
    } catch (Throwable t) {
        t.printStackTrace(System.err);
    }
}