Package junit.framework

Examples of junit.framework.Test


    }
   
    public static Test baseSuite(String name) {
        TestSuite suite = new TestSuite("AuthenticationTest");
       
        Test test = new AuthenticationTest(
            "testConnectShutdownAuthentication");
        setBaseProps(suite, test);
       
        test = new AuthenticationTest("testUserCasing");
        setBaseProps(suite, test);
View Full Code Here


        //       triggered when preparing a statement and this will interfere
        //       with some of the asserts in testUpdateStatistics.
        //       With automatic generation enabled, testUpdateStatistics may
        //       fail intermittently due to timing, mostly when run
        //       with the client driver.
        Test test = TestConfiguration.defaultSuite(UpdateStatisticsTest.class);
        Test statsDisabled = DatabasePropertyTestSetup.singleProperty
            ( test, "derby.storage.indexStats.auto", "false", true );

        return statsDisabled;
    }
View Full Code Here

        // Configure the tests
        @SuppressWarnings("unchecked")
        final Enumeration<Test> tests = testSuite.tests();
        while (tests.hasMoreElements())
        {
            final Test test = tests.nextElement();
            if (test instanceof AbstractProviderTestCase)
            {
                final AbstractProviderTestCase providerTestCase = (AbstractProviderTestCase) test;
                providerTestCase.setConfig(manager, providerConfig, baseFolder, readFolder, writeFolder);
            }
View Full Code Here

        props.setProperty("test.webdav.uri",
                "webdav://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
        props.setProperty("test.sftp.uri",
                "sftp://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");

        Test tests[] = new Test[]
        {
//          LocalProviderTestCase.suite(),
//          FtpProviderTestCase.suite(),
//          UrlProviderHttpTestCase.suite(),
//          VirtualProviderTestCase.suite(),
//          TemporaryProviderTestCase.suite(),
//          UrlProviderTestCase.suite(),
//          ResourceProviderTestCase.suite(),
//          HttpProviderTestCase.suite(),
//          SftpProviderTestCase.suite(),
//          JarProviderTestCase.suite(),
//          NestedJarTestCase.suite(),
//          ZipProviderTestCase.suite(),
//          NestedZipTestCase.suite(),
//          TarProviderTestCase.suite(),
//          TgzProviderTestCase.suite(),
//          Tbz2ProviderTestCase.suite(),
//          NestedTarTestCase.suite(),
//          NestedTgzTestCase.suite(),
//          NestedTbz2TestCase.suite(),
//          RamProviderTestCase.suite(),

// SmbProviderTestCase.suite(),
// WebdavProviderTestCase.suite(),
        };

        TestResult result = new TestResult()
        {
            @Override
            public void startTest(Test test)
            {
                System.out.println("start " + test);
                System.out.flush();
            }

            @Override
            public void endTest(Test test)
            {
                // System.err.println("end " + test);
            }

            @Override
            public synchronized void addError(Test test, Throwable throwable)
            {
                // throw new RuntimeException(throwable.getMessage());
                throwable.printStackTrace();
            }

            @Override
            public synchronized void addFailure(Test test,
                    AssertionFailedError assertionFailedError)
            {
                // throw new RuntimeException(assertionFailedError.getMessage());
                assertionFailedError.printStackTrace();
            }
        };

        for (int i = 0; i < tests.length; i++)
        {
            System.out.println("start test#" + i);
            System.out.flush();

            Test test = tests[i];
            test.run(result);

            // break;
        }
    }
View Full Code Here

        ByteArrayOutputStream errStrm = new ByteArrayOutputStream();
        ByteArrayOutputStream outStrm = new ByteArrayOutputStream();

        setupIOStreams(outStrm, errStrm);

        Test suite = null;
        Throwable exception = null;
        boolean startTestSuiteSuccess = false;

        try {

            try {
                Class testClass = null;
                if (loader == null) {
                    testClass = Class.forName(junitTest.getName());
                } else {
                    testClass = Class.forName(junitTest.getName(), true,
                                              loader);
                }

                final boolean testMethodsSpecified = (methods != null);

                // check for a static suite method first, even when using
                // JUnit 4
                Method suiteMethod = null;
                if (!testMethodsSpecified) {
                try {
                    // check if there is a suite method
                    suiteMethod = testClass.getMethod("suite", new Class[0]);
                } catch (NoSuchMethodException e) {
                    // no appropriate suite method found. We don't report any
                    // error here since it might be perfectly normal.
                }
                }

                if (suiteMethod != null) {
                    // if there is a suite method available, then try
                    // to extract the suite from it. If there is an error
                    // here it will be caught below and reported.
                    suite = (Test) suiteMethod.invoke(null, new Object[0]);

                } else {
                    Class junit4TestAdapterClass = null;
                    boolean useSingleMethodAdapter = false;

                    if (junit.framework.TestCase.class.isAssignableFrom(testClass)) {
                        // Do not use JUnit 4 API for running JUnit 3.x
                        // tests - it is not able to run individual test
                        // methods.
                        //
                        // Technical details:
                        // org.junit.runner.Request.method(Class, String).getRunner()
                        // would return a runner which always executes all
                        // test methods. The reason is that the Runner would be
                        // an instance of class
                        // org.junit.internal.runners.OldTestClassRunner
                        // that does not implement interface Filterable - so it
                        // is unable to filter out test methods not matching
                        // the requested name.
                    } else {
                    // Check for JDK 5 first. Will *not* help on JDK 1.4
                    // if only junit-4.0.jar in CP because in that case
                    // linkage of whole task will already have failed! But
                    // will help if CP has junit-3.8.2.jar:junit-4.0.jar.

                    // In that case first C.fN will fail with CNFE and we
                    // will avoid UnsupportedClassVersionError.

                    try {
                        Class.forName("java.lang.annotation.Annotation");
                        if (loader == null) {
                            junit4TestAdapterClass =
                                Class.forName(JUNIT_4_TEST_ADAPTER);
                            if (testMethodsSpecified) {
                                /*
                                 * We cannot try to load the JUnit4TestAdapter
                                 * before trying to load JUnit4TestMethodAdapter
                                 * because it might fail with
                                 * NoClassDefFoundException, instead of plain
                                 * ClassNotFoundException.
                                 */
                                junit4TestAdapterClass = Class.forName(
                                    "org.apache.tools.ant.taskdefs.optional.junit.JUnit4TestMethodAdapter");
                                useSingleMethodAdapter = true;
                            }
                        } else {
                            junit4TestAdapterClass =
                                Class.forName(JUNIT_4_TEST_ADAPTER,
                                              true, loader);
                            if (testMethodsSpecified) {
                                junit4TestAdapterClass =
                                    Class.forName(
                                        "org.apache.tools.ant.taskdefs.optional.junit.JUnit4TestMethodAdapter",
                                        true, loader);
                                useSingleMethodAdapter = true;
                            }
                        }
                    } catch (ClassNotFoundException e) {
                        // OK, fall back to JUnit 3.
                    }
                    }
                    junit4 = junit4TestAdapterClass != null;

                    if (junit4) {
                        // Let's use it!
                        Class[] formalParams;
                        Object[] actualParams;
                        if (useSingleMethodAdapter) {
                            formalParams = new Class[] {Class.class, String[].class};
                            actualParams = new Object[] {testClass, methods};
                        } else {
                            formalParams = new Class[] {Class.class, JUnit4TestAdapterCache.class};
                            actualParams = new Object[] {testClass, CustomJUnit4TestAdapterCache.getInstance()};
                        }
                        suite =
                            (Test) junit4TestAdapterClass
                            .getConstructor(formalParams).
                            newInstance(actualParams);
                    } else {
                        // Use JUnit 3.

                        // try to extract a test suite automatically this
                        // will generate warnings if the class is no
                        // suitable Test
                        if (!testMethodsSpecified) {
                            suite = new TestSuite(testClass);
                        } else if (methods.length == 1) {
                            suite = TestSuite.createTest(testClass, methods[0]);
                        } else {
                            TestSuite testSuite = new TestSuite(testClass.getName());
                            for (int i = 0; i < methods.length; i++) {
                                testSuite.addTest(
                                    TestSuite.createTest(testClass, methods[i]));
                            }
                            suite = testSuite;
                        }
                    }

                }

            } catch (Throwable e) {
                retCode = ERRORS;
                exception = e;
            }

            long start = System.currentTimeMillis();

            fireStartTestSuite();
            startTestSuiteSuccess = true;
            if (exception != null) { // had an exception constructing suite
                final int formatterSize = formatters.size();
                for (int i = 0; i < formatterSize; i++) {
                    ((TestListener) formatters.elementAt(i))
                        .addError(null, exception);
                }
                junitTest.setCounts(1, 0, 1, 0);
                junitTest.setRunTime(0);
            } else {
                try {
                    logTestListenerEvent("tests to run: " + suite.countTestCases());
                    suite.run(res);
                } finally {
                    if (junit4 ||
                        suite.getClass().getName().equals(JUNIT_4_TEST_ADAPTER)) {
                        int[] cnts = findJUnit4FailureErrorCount(res);
                        junitTest.setCounts(res.runCount() + res.ignoredCount(), cnts[0], cnts[1], res.ignoredCount() + res.skippedCount());
                    } else {
                        junitTest.setCounts(res.runCount() + res.ignoredCount(), res.failureCount(),
                                res.errorCount(), res.ignoredCount() + res.skippedCount());
View Full Code Here

            Enumeration<Test> e = ts.tests();

            while (e.hasMoreElements())
            {
                Test t = e.nextElement();
                setContext(t, ctx);
                ret.addTest(t);
            }

            return ret;
        }
        catch (final NoClassDefFoundError e)
        {
            TestSuite s = new TestSuite(test);
            s.addTest(new Test()
            {
                public int countTestCases()
                {
                    return 1;
                }

                public void run(TestResult result)
                {
                    result.addError(this, e);
                }
            });
            return s;
        }
        catch (final RuntimeException e)
        {
            TestSuite s = new TestSuite(test);
            s.addTest(new Test()
            {
                public int countTestCases()
                {
                    return 1;
                }
View Full Code Here

    public void testExceptionRunningAndTearDown() {
        // With 1.4, we should
        // wrap the exception thrown while running with the exception thrown
        // while tearing down
        Test t = new TornDown() {
            @Override
            public void tearDown() {
                throw new Error("tearingDown");
            }
        };
        TestResult result = new TestResult();
        t.run(result);
        TestFailure failure = result.errors().nextElement();
        assertEquals("running", failure.thrownException().getMessage());
    }
View Full Code Here

            assertSame(running, thrown);
        }
    }

    public void testNoArgTestCasePasses() {
        Test t = new TestSuite(NoArgTestCaseTest.class);
        TestResult result = new TestResult();
        t.run(result);
        assertTrue(result.runCount() == 1);
        assertTrue(result.failureCount() == 0);
        assertTrue(result.errorCount() == 0);
    }
View Full Code Here

        public void runTest() {
        }
    }

    public void testActiveTest() {
        Test test = createActiveTestSuite();
        TestResult result = new TestResult();
        test.run(result);
        assertEquals(100, result.runCount());
        assertEquals(0, result.failureCount());
        assertEquals(0, result.errorCount());
    }
View Full Code Here

        assertEquals(0, result.failureCount());
        assertEquals(0, result.errorCount());
    }

    public void testActiveRepeatedTest() {
        Test test = new RepeatedTest(createActiveTestSuite(), 5);
        TestResult result = new TestResult();
        test.run(result);
        assertEquals(500, result.runCount());
        assertEquals(0, result.failureCount());
        assertEquals(0, result.errorCount());
    }
View Full Code Here

TOP

Related Classes of junit.framework.Test

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.