Search in sources :

Example 21 with TestResult

use of junit.framework.TestResult in project android_frameworks_base by crdroidandroid.

the class InstrumentationTestSuiteBuilderTest method runSuite.

private SuiteExecutionRecorder runSuite(TestSuiteBuilder builder) {
    TestSuite suite = builder.build();
    SuiteExecutionRecorder recorder = new SuiteExecutionRecorder();
    TestResult result = new TestResult();
    result.addListener(recorder);
    suite.run(result);
    return recorder;
}
Also used : TestSuite(junit.framework.TestSuite) TestResult(junit.framework.TestResult)

Example 22 with TestResult

use of junit.framework.TestResult in project android_frameworks_base by crdroidandroid.

the class UnitTestSuiteBuilderTest method runSuite.

private SuiteExecutionRecorder runSuite(TestSuiteBuilder builder) {
    TestSuite suite = builder.build();
    SuiteExecutionRecorder recorder = new SuiteExecutionRecorder();
    TestResult result = new TestResult();
    result.addListener(recorder);
    suite.run(result);
    return recorder;
}
Also used : TestSuite(junit.framework.TestSuite) TestResult(junit.framework.TestResult)

Example 23 with TestResult

use of junit.framework.TestResult in project ofbiz-framework by apache.

the class TestRunContainer method start.

public boolean start() throws ContainerException {
    boolean failedRun = false;
    for (ModelTestSuite modelSuite : jsWrapper.getModelTestSuites()) {
        // prepare
        TestSuite suite = modelSuite.makeTestSuite();
        JUnitTest test = new JUnitTest(suite.getName());
        JunitXmlListener xml = createJunitXmlListener(suite, logDir);
        TestResult results = new TestResult();
        results.addListener(new JunitListener());
        results.addListener(xml);
        // test
        xml.startTestSuite(test);
        suite.run(results);
        test.setCounts(results.runCount(), results.failureCount(), results.errorCount());
        // rollback all entity operations
        modelSuite.getDelegator().rollback();
        xml.endTestSuite(test);
        logTestSuiteResults(suite, results);
        failedRun = !results.wasSuccessful() ? true : failedRun;
    }
    if (failedRun) {
        throw new ContainerException("Test run was unsuccessful");
    }
    return true;
}
Also used : JUnitTest(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest) TestSuite(junit.framework.TestSuite) ContainerException(org.apache.ofbiz.base.container.ContainerException) TestResult(junit.framework.TestResult)

Example 24 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 25 with TestResult

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

the class TestRunner method execute.

/**
 * Execute the specific test against the specified participant.
 * @param participantURI The URI of the participant.
 * @param testTimeout The test timeout.
 * @param asyncTest The asynchronous test flag.
 * @param testName The name of the test to execute.
 * @return The test result.
 */
public static TestResult execute(final String participantURI, final long testTimeout, final boolean asyncTest, final String testName) {
    MessageLogging.clearThreadLog();
    final Test test;
    if (TestConstants.NAME_ALL_TESTS.equals(testName)) {
        final TestSuite testSuite = new TestSuite();
        testSuite.addTest(new InteropTestSuite(participantURI, testTimeout, asyncTest, SC007_TEST_CLASS));
        test = testSuite;
    } else if (testName.startsWith(TestConstants.PREFIX_TESTS)) {
        final Class testClass = SC007_TEST_CLASS;
        try {
            test = createTest(testClass, participantURI, testTimeout, asyncTest, testName);
        } catch (final Throwable th) {
            System.err.println("Unexpected error instantiating test class: " + th);
            return null;
        }
    } else {
        System.err.println("Unidentified test name: " + testName);
        return null;
    }
    MessageLogging.appendThreadLog(LOG_MESSAGE_PREFIX);
    final TestResult testResult = new FullTestResult();
    test.run(testResult);
    MessageLogging.appendThreadLog(LOG_MESSAGE_SUFFIX);
    return testResult;
}
Also used : InteropTestSuite(com.jboss.transaction.wstf.interop.InteropTestSuite) TestSuite(junit.framework.TestSuite) InteropTestSuite(com.jboss.transaction.wstf.interop.InteropTestSuite) Test(junit.framework.Test) TestResult(junit.framework.TestResult)

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