Search in sources :

Example 26 with TestResult

use of junit.framework.TestResult in project narayana by jbosstm.

the class TestServlet method doPost.

/**
 * Execute the test
 * @param request The HTTP servlet request.
 * @param response The HTTP servlet response.
 */
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    final String serviceURI = request.getParameter(TestConstants.PARAM_SERVICE_URI);
    final String test = request.getParameter(TestConstants.PARAM_TEST);
    final String testTimeoutValue = request.getParameter(TestConstants.PARAM_TEST_TIMEOUT);
    // final String asyncTestValue = request.getParameter(TestConstants.PARAM_ASYNC_TEST) ;
    String resultPageAddress = request.getParameter(TestConstants.PARAM_RESULT_PAGE);
    if (resultPageAddress == null || resultPageAddress.length() == 0) {
        resultPageAddress = TestConstants.DEFAULT_RESULT_PAGE_ADDRESS;
    }
    final int serviceURILength = (serviceURI == null ? 0 : serviceURI.length());
    final int testLength = (test == null ? 0 : test.length());
    long testTimeout = 0;
    boolean testTimeoutValid = false;
    if ((testTimeoutValue != null) && (testTimeoutValue.length() > 0)) {
        try {
            testTimeout = Long.parseLong(testTimeoutValue);
            testTimeoutValid = true;
        }// ignore
         catch (final NumberFormatException nfe) {
        }
    }
    // final boolean asyncTest = (asyncTestValue != null) ;
    final boolean asyncTest = true;
    if ((serviceURILength == 0) || (testLength == 0) || !testTimeoutValid) {
        final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/invalidParameters.html");
        dispatcher.forward(request, response);
        return;
    }
    final HttpSession session = request.getSession();
    final String id = session.getId();
    final int logCount = getLogCount(session);
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    final String date = format.format(new Date());
    final String logName = date + "-" + id + "-" + logCount;
    session.setAttribute(TestConstants.ATTRIBUTE_TEST_RESULT, null);
    session.setAttribute(TestConstants.ATTRIBUTE_TEST_VALIDATION, null);
    session.setAttribute(TestConstants.ATTRIBUTE_LOG_NAME, null);
    final String threadLog;
    try {
        final TestResult result = TestRunner.execute(serviceURI, testTimeout, asyncTest, test);
        if (result != null) {
            session.setAttribute(TestConstants.ATTRIBUTE_TEST_RESULT, result);
            threadLog = MessageLogging.getThreadLog();
            try {
                TestLogController.writeLog(logName, threadLog);
                session.setAttribute(TestConstants.ATTRIBUTE_LOG_NAME, logName);
            } catch (final IOException ioe) {
                log("Unexpected IOException writing message log", ioe);
            }
        } else {
            threadLog = null;
        }
    } finally {
        MessageLogging.clearThreadLog();
    }
    if ((threadLog != null) && (threadLog.length() > 0)) {
        try {
            final String testValidation = transform(threadLog);
            session.setAttribute(TestConstants.ATTRIBUTE_TEST_VALIDATION, testValidation);
        } catch (final Throwable th) {
            log("Unexpected throwable transforming message log", th);
        }
    }
    final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(resultPageAddress);
    dispatcher.forward(request, response);
}
Also used : HttpSession(javax.servlet.http.HttpSession) TestResult(junit.framework.TestResult) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) RequestDispatcher(javax.servlet.RequestDispatcher) Date(java.util.Date)

Example 27 with TestResult

use of junit.framework.TestResult in project ecf by eclipse.

the class TestActivator method startTests.

protected void startTests() {
    final TestSuite suite = new TestSuite();
    final TestResult result = new TestResult();
    final JUnitTest jUnitTest = new JUnitTest("ch.ethz.iks.slp.test");
    jUnitTest.setProperties(System.getProperties());
    // create the xml result formatter
    final JUnitResultFormatter xmlResultFormatter = new XMLJUnitResultFormatter();
    final File file = new File(outputDirectory, "TEST-ch.ethz.iks.slp.test" + ".xml");
    try {
        xmlResultFormatter.setOutput(new FileOutputStream(file));
    } catch (FileNotFoundException e) {
        // may never happen
        e.printStackTrace();
    }
    result.addListener(xmlResultFormatter);
    // create a result formatter that prints to the console
    final JUnitResultFormatter consoleResultFormatter = new BriefJUnitResultFormatter();
    consoleResultFormatter.setOutput(System.out);
    result.addListener(consoleResultFormatter);
    // add the actual tests to the test suite
    Collection collection = new ArrayList();
    collection.add(SelfDiscoveryTest.class);
    for (Iterator iterator = collection.iterator(); iterator.hasNext(); ) {
        Class clazz = (Class) iterator.next();
        // run all methods starting with "test*"
        Method[] methods = clazz.getMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().startsWith("test")) {
                TestCase testCase;
                try {
                    testCase = (TestCase) clazz.newInstance();
                    testCase.setName(methods[i].getName());
                    suite.addTest(testCase);
                } catch (InstantiationException e) {
                    // may never happen
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // may never happen
                    e.printStackTrace();
                }
            }
        }
    }
    // prepare to run tests
    final long start = System.currentTimeMillis();
    xmlResultFormatter.startTestSuite(jUnitTest);
    consoleResultFormatter.startTestSuite(jUnitTest);
    // run tests
    suite.run(result);
    // write stats and close reultformatter
    jUnitTest.setCounts(result.runCount(), result.failureCount(), result.errorCount());
    jUnitTest.setRunTime(System.currentTimeMillis() - start);
    xmlResultFormatter.endTestSuite(jUnitTest);
    consoleResultFormatter.endTestSuite(jUnitTest);
    // print success of failure
    if (result.wasSuccessful()) {
        System.exit(0);
    } else {
        if (result.errorCount() > 0) {
            System.err.println("Errors:");
            for (Enumeration errors = result.errors(); errors.hasMoreElements(); ) {
                TestFailure error = (TestFailure) errors.nextElement();
                System.err.println(error.trace());
            }
        }
        if (result.failureCount() > 0) {
            System.err.println("Failures:");
            for (Enumeration failures = result.failures(); failures.hasMoreElements(); ) {
                TestFailure failure = (TestFailure) failures.nextElement();
                System.err.println(failure.trace());
            }
        }
        System.exit(1);
    }
    ;
}
Also used : Enumeration(java.util.Enumeration) TestFailure(junit.framework.TestFailure) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) TestResult(junit.framework.TestResult) Method(java.lang.reflect.Method) BriefJUnitResultFormatter(org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter) JUnitResultFormatter(org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter) XMLJUnitResultFormatter(org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter) JUnitTest(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest) TestSuite(junit.framework.TestSuite) TestCase(junit.framework.TestCase) XMLJUnitResultFormatter(org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) Collection(java.util.Collection) File(java.io.File) BriefJUnitResultFormatter(org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter)

Example 28 with TestResult

use of junit.framework.TestResult in project derby by apache.

the class NullableUniqueConstraintTest method main.

public static void main(String[] args) {
    TestResult tr = new TestResult();
    Test t = suite();
    t.run(tr);
    System.out.println(tr.errorCount());
    Enumeration e = tr.failures();
    while (e.hasMoreElements()) {
        ((TestFailure) e.nextElement()).thrownException().printStackTrace();
    }
    System.out.println(tr.failureCount());
}
Also used : Enumeration(java.util.Enumeration) Test(junit.framework.Test) TestResult(junit.framework.TestResult)

Example 29 with TestResult

use of junit.framework.TestResult in project openj9 by eclipse.

the class TestManager method main.

/*This is the entry point to JIT code cache Test harness.*/
public static void main(String[] args) {
    /*Obtain the JIT log file being used*/
    jitLogFileName = getLogFileName();
    if (jitLogFileName == null) {
        System.out.println("Can not find JIT log file path, please ensure your JIT verbose log file name is of format <filename>.log");
        return;
    } else {
        System.out.println("JIT verbose log file being used : " + jitLogFileName);
    }
    /*Obtain the basic command line arguments*/
    Options options = getOptions();
    CommandLineParser parser = new PosixParser();
    CommandLine cmdLine = null;
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException e) {
        e.printStackTrace();
        System.out.println("Error parsing command line input");
        return;
    }
    if (cmdLine.hasOption(Constants.JAR_DIR)) {
        jarDir = cmdLine.getOptionValue(Constants.JAR_DIR);
        if (new File(jarDir).exists() == false) {
            System.out.println("Invalid location provided for jar directories : " + jarDir);
            return;
        } else {
            System.out.println("Jar location : " + jarDir);
        }
    } else {
        System.out.println("Please provide Jar Directory path");
        printUsage(options);
        return;
    }
    /*Prepare Junit test suite according to command line user options*/
    TestSuite ts = new TestSuite();
    if (cmdLine.hasOption(Constants.CCTEST_BASIC)) {
        ts.addTestSuite(BasicTest.class);
    }
    if (cmdLine.hasOption(Constants.CCTEST_BOUNDARY)) {
        if (ts.testCount() == 0) {
            ts.addTestSuite(BoundaryTest.class);
        } else {
            System.out.println("Boundary test must not be run with other tests");
            return;
        }
    }
    if (cmdLine.hasOption(Constants.CCTEST_SPACE_REUSE)) {
        ts.addTestSuite(SpaceReuseTest.class);
    }
    if (cmdLine.hasOption(Constants.CCTEST_TRAMPOLINE_BASIC)) {
        ts.addTestSuite(TrampolineTest_Basic.class);
    }
    if (cmdLine.hasOption(Constants.CCTEST_TRAMPOLINE_ADVANCED)) {
        ts.addTestSuite(TrampolineTest_Advanced.class);
    }
    if (cmdLine.hasOption(Constants.CCTEST_TRAMPOLINE_IPIC)) {
        ts.addTestSuite(TrampolineTest_IPIC.class);
    }
    if (cmdLine.hasOption(Constants.CCTEST_AOT_PHASE1)) {
        loadAot();
    }
    if (cmdLine.hasOption(Constants.CCTEST_AOT_PHASE2)) {
        ts.addTestSuite(AOTTest.class);
    }
    TestResult result = new TestResult();
    result.addListener(new TestListener() {

        public void addError(Test test, Throwable t) {
            t.printStackTrace(System.err);
        }

        public void addFailure(Test test, AssertionFailedError t) {
            t.printStackTrace(System.err);
        }

        public void endTest(Test test) {
            System.out.println("Finished " + test + System.getProperty("line.separator"));
        }

        public void startTest(Test test) {
            System.out.println("Starting " + test);
        }
    });
    /*Start child threads with appropriate options*/
    if (cmdLine.hasOption(Constants.CCTEST_BASIC) || cmdLine.hasOption(Constants.CCTEST_SPACE_REUSE)) {
        startLogParserInBackground(Constants.BASIC_TEST);
        // Basic tests requires class unloading and method reclamation, so use multiple class loaders.
        // Use a single class compilation thread .
        startCompilationInBackground(true, false);
    }
    /*Start code cache tests*/
    ts.run(result);
    if (cmdLine.hasOption(Constants.CCTEST_BASIC) || cmdLine.hasOption(Constants.CCTEST_SPACE_REUSE)) {
        /*Shutdown child threads*/
        if (shutdownBackgroundProcesses()) {
            System.out.println("Info : TestManager: Code Cache Test Harness shutdown complete");
        } else {
            System.out.println("WARNING: TestManager: Failed to shut down Code Cache Test harness");
        // TODO: We should have a Junit failure at this point
        }
    }
    /*Show result statistics*/
    System.out.println("================Test Result for ==================");
    System.out.println("Errors:   " + result.errorCount() + " out of " + ts.countTestCases() + " test cases.");
    System.out.println("Failures: " + result.failureCount() + " out of " + ts.countTestCases() + " test cases.");
    System.out.println("Total Error/Failures: " + (result.errorCount() + result.failureCount()));
    if ((result.errorCount() + result.failureCount()) > 0) {
        System.exit(-2);
    } else {
        System.exit(0);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) TestSuite(junit.framework.TestSuite) Test(junit.framework.Test) PosixParser(org.apache.commons.cli.PosixParser) TestResult(junit.framework.TestResult) TestListener(junit.framework.TestListener) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File)

Example 30 with TestResult

use of junit.framework.TestResult in project eclipse.platform.releng by eclipse.

the class EclipseTestRunner method run.

public void run() {
    // IPerformanceMonitor pm =
    // PerfMsrCorePlugin.getPerformanceMonitor(true);
    fTestResult = new TestResult();
    fTestResult.addListener(this);
    for (int i = 0; i < formatters.size(); i++) {
        fTestResult.addListener(formatters.elementAt(i));
    }
    long start = System.currentTimeMillis();
    fireStartTestSuite();
    if (fException != null) {
        // had an exception in the constructor
        for (int i = 0; i < formatters.size(); i++) {
            formatters.elementAt(i).addError(null, fException);
        }
        fJunitTest.setCounts(1, 0, 1);
        fJunitTest.setRunTime(0);
    } else {
        ByteArrayOutputStream errStrm = new ByteArrayOutputStream();
        fSystemError = new PrintStream(errStrm);
        ByteArrayOutputStream outStrm = new ByteArrayOutputStream();
        fSystemOut = new PrintStream(outStrm);
        try {
            // pm.snapshot(1); // before
            fSuite.run(fTestResult);
        } finally {
            // pm.snapshot(2); // after
            fSystemError.close();
            fSystemError = null;
            fSystemOut.close();
            fSystemOut = null;
            sendOutAndErr(new String(outStrm.toByteArray()), new String(errStrm.toByteArray()));
            fJunitTest.setCounts(fTestResult.runCount(), fTestResult.failureCount(), fTestResult.errorCount());
            fJunitTest.setRunTime(System.currentTimeMillis() - start);
        }
    }
    fireEndTestSuite();
    if (fRetCode != SUCCESS || fTestResult.errorCount() != 0) {
        fRetCode = ERRORS;
    } else if (fTestResult.failureCount() != 0) {
        fRetCode = FAILURES;
    }
// pm.upload(getClass().getName());
}
Also used : PrintStream(java.io.PrintStream) TestResult(junit.framework.TestResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

TestResult (junit.framework.TestResult)108 TestSuite (junit.framework.TestSuite)33 Test (junit.framework.Test)19 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)17 TestCase (junit.framework.TestCase)14 TestFailure (junit.framework.TestFailure)12 Test (org.junit.Test)10 TestListener (junit.framework.TestListener)9 ArrayList (java.util.ArrayList)8 PrintStream (java.io.PrintStream)7 RepeatedTest (junit.extensions.RepeatedTest)7 Enumeration (java.util.Enumeration)6 Bundle (android.os.Bundle)5 HandlerThread (android.os.HandlerThread)5 ShellUiAutomatorBridge (com.android.uiautomator.core.ShellUiAutomatorBridge)5 Tracer (com.android.uiautomator.core.Tracer)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5 AssertionFailedError (junit.framework.AssertionFailedError)5 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4