Package org.junit.runner

Examples of org.junit.runner.JUnitCore


    }

    /** @inheritDoc */
    public void executeTests(Collection<String> testNames, Renderer renderer, TestSelector selector) throws Exception {
        renderer.title(2, "Running tests");
        final JUnitCore junit = new JUnitCore();
       
        // Create a test context if we don't have one yet
        final boolean createContext =  !SlingTestContextProvider.hasContext();
        if(createContext) {
            SlingTestContextProvider.createContext();
        }
       
        try {
            junit.addListener(new TestContextRunListenerWrapper(renderer.getRunListener()));
            for(String className : testNames) {
                renderer.title(3, className);
               
                // If we have a test context, clear its output metadata
                if(SlingTestContextProvider.hasContext()) {
                    SlingTestContextProvider.getContext().output().clear();
                }
               
                final String testMethodName = selector == null ? null : selector.getSelectedTestMethodName();
                if(testMethodName != null && testMethodName.length() > 0) {
                    log.debug("Running test method {} from test class {}", testMethodName, className);
                    junit.run(Request.method(getTestClass(className), testMethodName));
                } else {
                    log.debug("Running test class {}", className);
                    junit.run(getTestClass(className));
                }
            }
        } finally {
            if(createContext) {
                SlingTestContextProvider.deleteContext();
View Full Code Here


    }

    @Test
    public void runTestAndVerifyResult() {
        EventCollector collector = new EventCollector();
        JUnitCore core = new JUnitCore();
        core.addListener(collector);
        core.run(classUnderTest);
        assertThat(collector, matcher);
    }
View Full Code Here

    public static class InheritsAll extends All {
    }

    @Test
    public void ensureTestIsRun() {
        JUnitCore core = new JUnitCore();
        Result result = core.run(All.class);
        assertEquals(2, result.getRunCount());
        assertEquals(1, result.getFailureCount());
    }
View Full Code Here

        }
    }

    @Test
    public void ignoreRunner() {
        JUnitCore runner = new JUnitCore();
        Result result = runner.run(IgnoredTest.class);
        assertEquals(2, result.getIgnoreCount());
        assertEquals(1, result.getRunCount());
    }
View Full Code Here

        assertEquals(1, result.getFailureCount());
    }

    @Test
    public void ensureInheritedTestIsRun() {
        JUnitCore core = new JUnitCore();
        Result result = core.run(InheritsAll.class);
        assertEquals(2, result.getRunCount());
        assertEquals(1, result.getFailureCount());
    }
View Full Code Here

        }
    }

    public void testOneTimeTeardown() throws Exception {
        count = 0;
        JUnitCore core = new JUnitCore();
        core.run(OneTimeTeardown.class);
        assertEquals(1, count);
    }
View Full Code Here

        }
    }

    public void testOrder() throws Exception {
        log = "";
        JUnitCore core = new JUnitCore();
        core.run(OrderTest.class);
        assertEquals("beforeClass before test after afterClass ", log);
    }
View Full Code Here

        public void aTest() {
        }
    }

    public void testNonStaticOneTimeSetup() throws Exception {
        JUnitCore core = new JUnitCore();
        Result result = core.run(NonStaticOneTimeSetup.class);
        assertEquals(1, result.getFailureCount());
    }
View Full Code Here

        }
    }

    public void testErrorInBeforeClass() throws Exception {
        run = false;
        JUnitCore core = new JUnitCore();
        Result result = core.run(ErrorInBeforeClass.class);
        assertFalse(run);
        assertEquals(1, result.getFailureCount());
        Description description = result.getFailures().get(0).getDescription();
        assertEquals(ErrorInBeforeClass.class.getName(), description.getDisplayName());
    }
View Full Code Here

        }
    }

    public void testErrorInAfterClass() throws Exception {
        run = false;
        JUnitCore core = new JUnitCore();
        Result result = core.run(ErrorInAfterClass.class);
        assertTrue(run);
        assertEquals(1, result.getFailureCount());
    }
View Full Code Here

TOP

Related Classes of org.junit.runner.JUnitCore

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.