Search in sources :

Example 1 with TestRunner

use of junit.textui.TestRunner in project junit4 by junit-team.

the class TextRunnerSingleMethodTest method testSingle.

public void testSingle() throws Exception {
    TestRunner t = new TestRunner();
    t.setPrinter(new ResultPrinter(new PrintStream(new ByteArrayOutputStream())));
    String[] args = { "-m", "junit.tests.runner.TextRunnerSingleMethodTest$InvocationTest.testWasInvoked" };
    fgWasInvoked = false;
    t.start(args);
    assertTrue(fgWasInvoked);
}
Also used : PrintStream(java.io.PrintStream) ResultPrinter(junit.textui.ResultPrinter) TestRunner(junit.textui.TestRunner) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with TestRunner

use of junit.textui.TestRunner in project junit4 by junit-team.

the class ForwardCompatibilityPrintingTest method testErrorAdapted.

public void testErrorAdapted() {
    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);
    runner.doRun(new JUnit4TestAdapter(ATest.class));
    assertEquals(expected, output.toString());
}
Also used : PrintStream(java.io.PrintStream) ResultPrinter(junit.textui.ResultPrinter) TestRunner(junit.textui.TestRunner) TestResult(junit.framework.TestResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JUnit4TestAdapter(junit.framework.JUnit4TestAdapter)

Example 3 with TestRunner

use of junit.textui.TestRunner 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 4 with TestRunner

use of junit.textui.TestRunner in project kotlin by JetBrains.

the class StdlibTest method testStdlib.

public void testStdlib() throws ClassNotFoundException {
    GenerationState state = KotlinToJVMBytecodeCompiler.INSTANCE.analyzeAndGenerate(getEnvironment());
    if (state == null) {
        fail("There were compilation errors");
    }
    classLoader = new GeneratedClassLoader(state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()) {

        @Override
        public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
            if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
                return StdlibTest.class.getClassLoader().loadClass(name);
            }
            return super.loadClass(name);
        }
    };
    TestSuite tests = new TestSuite("Standard Library Tests");
    for (KtFile file : getEnvironment().getSourceFiles()) {
        // Skip JS tests
        if (file.getVirtualFile().getPath().contains("/js/"))
            continue;
        for (KtDeclaration declaration : file.getDeclarations()) {
            if (!(declaration instanceof KtClass))
                continue;
            ClassDescriptor descriptor = (ClassDescriptor) BindingContextUtils.getNotNull(state.getBindingContext(), BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
            Test test = createTest(classLoader, state.getTypeMapper().mapClass(descriptor).getClassName());
            if (test != null) {
                tests.addTest(test);
            }
        }
    }
    TestResult result = new TestRunner(System.err).doRun(tests);
    if (!result.wasSuccessful()) {
        fail("Some stdlib tests failed, see stderr for details");
    }
}
Also used : ClassDescriptor(org.jetbrains.kotlin.descriptors.ClassDescriptor) TestRunner(junit.textui.TestRunner) KtClass(org.jetbrains.kotlin.psi.KtClass) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) KtDeclaration(org.jetbrains.kotlin.psi.KtDeclaration) KtClass(org.jetbrains.kotlin.psi.KtClass) KtFile(org.jetbrains.kotlin.psi.KtFile)

Example 5 with TestRunner

use of junit.textui.TestRunner in project junit4 by junit-team.

the class TextFeedbackTest method setUp.

@Override
public void setUp() {
    output = new ByteArrayOutputStream();
    runner = new TestRunner(new TestResultPrinter(new PrintStream(output)));
}
Also used : PrintStream(java.io.PrintStream) TestRunner(junit.textui.TestRunner) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

TestRunner (junit.textui.TestRunner)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 ResultPrinter (junit.textui.ResultPrinter)3 TestResult (junit.framework.TestResult)2 JUnit4TestAdapter (junit.framework.JUnit4TestAdapter)1 TestCase (junit.framework.TestCase)1 TestSuite (junit.framework.TestSuite)1 GenerationState (org.jetbrains.kotlin.codegen.state.GenerationState)1 ClassDescriptor (org.jetbrains.kotlin.descriptors.ClassDescriptor)1 KtClass (org.jetbrains.kotlin.psi.KtClass)1 KtDeclaration (org.jetbrains.kotlin.psi.KtDeclaration)1 KtFile (org.jetbrains.kotlin.psi.KtFile)1