Search in sources :

Example 16 with TestCase

use of junit.framework.TestCase in project junit4 by junit-team.

the class TestListenerTest method testError.

public void testError() {
    TestCase test = new TestCase("noop") {

        @Override
        public void runTest() {
            throw new Error();
        }
    };
    test.run(fResult);
    assertEquals(1, fErrorCount);
    assertEquals(1, fEndCount);
}
Also used : TestCase(junit.framework.TestCase) AssertionFailedError(junit.framework.AssertionFailedError)

Example 17 with TestCase

use of junit.framework.TestCase in project junit4 by junit-team.

the class TestCaseTest method testSetupFails.

public void testSetupFails() {
    TestCase fails = new TestCase("success") {

        @Override
        protected void setUp() {
            throw new Error();
        }

        @Override
        protected void runTest() {
        }
    };
    verifyError(fails);
}
Also used : TestCase(junit.framework.TestCase)

Example 18 with TestCase

use of junit.framework.TestCase in project junit4 by junit-team.

the class ForwardCompatibilityPrintingTest method testError.

public void testError() {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    TestRunner runner = new TestRunner(new TestResultPrinter(new PrintStream(output)));
    String expected = expected(new String[] { ".E", "Time: 0", "Errors here", "", "FAILURES!!!", "Tests run: 1,  Failures: 0,  Errors: 1", "" });
    ResultPrinter printer = new TestResultPrinter(new PrintStream(output)) {

        @Override
        public void printErrors(TestResult result) {
            getWriter().println("Errors here");
        }
    };
    runner.setPrinter(printer);
    TestSuite suite = new TestSuite();
    suite.addTest(new TestCase() {

        @Override
        public void runTest() throws Exception {
            throw new Exception();
        }
    });
    runner.doRun(suite);
    assertEquals(expected, output.toString());
}
Also used : PrintStream(java.io.PrintStream) TestSuite(junit.framework.TestSuite) ResultPrinter(junit.textui.ResultPrinter) TestCase(junit.framework.TestCase) TestRunner(junit.textui.TestRunner) TestResult(junit.framework.TestResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 19 with TestCase

use of junit.framework.TestCase in project junit4 by junit-team.

the class OldTestClassAdaptingListenerTest method addFailureDelegatesToNotifier.

@Test
public void addFailureDelegatesToNotifier() {
    Result result = new Result();
    RunListener listener = result.createListener();
    RunNotifier notifier = new RunNotifier();
    notifier.addFirstListener(listener);
    TestCase testCase = new TestCase() {
    };
    TestListener adaptingListener = new JUnit38ClassRunner(testCase).createAdaptingListener(notifier);
    adaptingListener.addFailure(testCase, new AssertionFailedError());
    assertEquals(1, result.getFailureCount());
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) TestCase(junit.framework.TestCase) JUnit38ClassRunner(org.junit.internal.runners.JUnit38ClassRunner) TestListener(junit.framework.TestListener) AssertionFailedError(junit.framework.AssertionFailedError) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener) Test(org.junit.Test)

Example 20 with TestCase

use of junit.framework.TestCase in project android-junit-report by jsankey.

the class JUnitReportListener method startTest.

@Override
public void startTest(Test test) {
    try {
        if (test instanceof TestCase) {
            TestCase testCase = (TestCase) test;
            checkForNewSuite(testCase);
            mSerializer.startTag("", TAG_CASE);
            mSerializer.attribute("", ATTRIBUTE_CLASS, mCurrentSuite);
            mSerializer.attribute("", ATTRIBUTE_NAME, testCase.getName());
            mTimeAlreadyWritten = false;
            mTestStartTime = System.currentTimeMillis();
        }
    } catch (IOException e) {
        Log.e(LOG_TAG, safeMessage(e));
    }
}
Also used : TestCase(junit.framework.TestCase) IOException(java.io.IOException)

Aggregations

TestCase (junit.framework.TestCase)129 TestSuite (junit.framework.TestSuite)36 Test (junit.framework.Test)22 TestListener (junit.framework.TestListener)17 TestResult (junit.framework.TestResult)13 ArrayList (java.util.ArrayList)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 AssertionFailedError (junit.framework.AssertionFailedError)10 Constructor (java.lang.reflect.Constructor)8 Enumeration (java.util.Enumeration)6 Context (android.content.Context)5 PackageManager (android.content.pm.PackageManager)5 ResolveInfo (android.content.pm.ResolveInfo)5 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 Field (java.lang.reflect.Field)5 HashSet (java.util.HashSet)5