Search in sources :

Example 11 with TextListener

use of org.junit.internal.TextListener in project junit4 by junit-team.

the class TextListenerTest method setUp.

@Override
public void setUp() {
    runner = new JUnitCore();
    TestSystem system = new TestSystem();
    results = system.outContents();
    runner.addListener(new TextListener(system));
}
Also used : JUnitCore(org.junit.runner.JUnitCore) TestSystem(org.junit.tests.TestSystem) TextListener(org.junit.internal.TextListener)

Example 12 with TextListener

use of org.junit.internal.TextListener in project mockito by mockito.

the class MockitoRunnerBreaksWhenNoTestMethodsTest method ensure_the_test_runner_breaks.

@Test
public void ensure_the_test_runner_breaks() throws Exception {
    JUnitCore runner = new JUnitCore();
    //        runner.addListener(new TextListener(System.out));
    runner.addListener(new TextListener(DevNull.out));
    Result result = runner.run(TestClassWithoutTestMethod.class);
    assertEquals(1, result.getFailureCount());
    assertTrue(result.getFailures().get(0).getException() instanceof MockitoException);
    assertFalse(result.wasSuccessful());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) MockitoException(org.mockito.exceptions.base.MockitoException) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 13 with TextListener

use of org.junit.internal.TextListener in project ACS by ACS-Community.

the class TATJUnitRunner method runMain.

/**
	 * Modified version of {@link JUnitCore#runMain(JUnitSystem, String...)}.
	 * We restrict ourselves to running only one test class (or suite) at a time.
	 * This method is not thread-safe!
	 * @param testClass
	 * @return the result
	 * @throws IOException 
	 */
public Result runMain(Class<?> testClass) throws IOException {
    Result result = null;
    try {
        keepTestOutput = testClass.isAnnotationPresent(KeepTestOutput.class);
        createStreams(testClass);
        redirectSysStreams();
        JUnitSystem system = new JUnitSystem() {

            public void exit(int code) {
                System.exit(code);
            }

            public PrintStream out() {
                return resultOut;
            }
        };
        system.out().println("JUnit version " + Version.id());
        RunListener listener = new TextListener(system);
        // or should we listen directly?
        delegate.addListener(listener);
        result = delegate.run(testClass);
    } finally {
        restoreSysStreams();
        closeStreams();
    }
    // in either case print a summary which automated tools can analyze (SPR ALMASW2005121)
    int total = result.getRunCount();
    int success = total - result.getFailureCount();
    String runnerReport = "TEST_RUNNER_REPORT success/total: " + success + "/" + total;
    System.out.println(runnerReport);
    if (result.wasSuccessful()) {
        System.out.println("JUnit test run succeeded");
        if (!keepTestOutput) {
            sysOutFile.delete();
            sysErrFile.delete();
            resultFile.delete();
        }
    } else {
        System.err.println("JUnitRunner: Errors and/or failures during test execution!\n");
        // Dump the JUnit test runner output, the captured stdout, and the captured stderr of the text execution to System.err. 
        dumpAndDeleteCapturedFile(resultFile, "Test execution trace:");
        dumpAndDeleteCapturedFile(sysOutFile, "System.out during test execution:");
        dumpAndDeleteCapturedFile(sysErrFile, "System.err during test execution:");
    }
    return result;
}
Also used : JUnitSystem(org.junit.internal.JUnitSystem) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) RunListener(org.junit.runner.notification.RunListener)

Example 14 with TextListener

use of org.junit.internal.TextListener in project android by JetBrains.

the class PlainJUnitRunnable method run.

@Override
public void run() {
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TextListener(System.out));
    if (!junit.run(Request.aClass(mSuiteClass)).wasSuccessful()) {
        System.exit(1);
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) TextListener(org.junit.internal.TextListener)

Example 15 with TextListener

use of org.junit.internal.TextListener in project poi by apache.

the class OOXMLLite method build.

void build() throws IOException, ClassNotFoundException {
    List<Class<?>> lst = new ArrayList<Class<?>>();
    //collect unit tests
    String exclude = StringUtil.join("|", "BaseTestXWorkbook", "BaseTestXSheet", "BaseTestXRow", "BaseTestXCell", "BaseTestXSSFPivotTable", "TestSXSSFWorkbook\\$\\d", "TestUnfixedBugs", "MemoryUsage", "TestDataProvider", "TestDataSamples", "All.+Tests", "ZipFileAssert", "AesZipFileZipEntrySource", "TempFileRecordingSXSSFWorkbookWithCustomZipEntrySource", "PkiTestUtils", "TestCellFormatPart\\$\\d", "TestSignatureInfo\\$\\d", "TestCertificateEncryption\\$CertData", "TestPOIXMLDocument\\$OPCParser", "TestPOIXMLDocument\\$TestFactory", "TestXSLFTextParagraph\\$DrawTextParagraphProxy", "TestXSSFExportToXML\\$\\d", "TestXSSFExportToXML\\$DummyEntityResolver", "TestFormulaEvaluatorOnXSSF\\$Result", "TestFormulaEvaluatorOnXSSF\\$SS", "TestMultiSheetFormulaEvaluatorOnXSSF\\$Result", "TestMultiSheetFormulaEvaluatorOnXSSF\\$SS", "TestXSSFBugs\\$\\d");
    System.out.println("Collecting unit tests from " + _testDir);
    collectTests(_testDir, _testDir, lst, ".+.class$", ".+(" + exclude + ").class");
    System.out.println("Found " + lst.size() + " classes");
    //run tests
    JUnitCore jUnitCore = new JUnitCore();
    jUnitCore.addListener(new TextListener(System.out));
    Result result = jUnitCore.run(lst.toArray(new Class<?>[lst.size()]));
    if (!result.wasSuccessful()) {
        throw new RuntimeException("Tests did not succeed, cannot build ooxml-lite jar");
    }
    //see what classes from the ooxml-schemas.jar are loaded
    System.out.println("Copying classes to " + _destDest);
    Map<String, Class<?>> classes = getLoadedClasses(_ooxmlJar.getName());
    for (Class<?> cls : classes.values()) {
        String className = cls.getName();
        String classRef = className.replace('.', '/') + ".class";
        File destFile = new File(_destDest, classRef);
        copyFile(cls.getResourceAsStream('/' + classRef), destFile);
        if (cls.isInterface()) {
            /**
                 * Copy classes and interfaces declared as members of this class
                 */
            for (Class<?> fc : cls.getDeclaredClasses()) {
                className = fc.getName();
                classRef = className.replace('.', '/') + ".class";
                destFile = new File(_destDest, classRef);
                copyFile(fc.getResourceAsStream('/' + classRef), destFile);
            }
        }
    }
    //finally copy the compiled .xsb files
    System.out.println("Copying .xsb resources");
    JarFile jar = new JarFile(_ooxmlJar);
    Pattern p = Pattern.compile("schemaorg_apache_xmlbeans/(system|element)/.*\\.xsb");
    try {
        for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ) {
            JarEntry je = e.nextElement();
            if (p.matcher(je.getName()).matches()) {
                File destFile = new File(_destDest, je.getName());
                copyFile(jar.getInputStream(je), destFile);
            }
        }
    } finally {
        jar.close();
    }
}
Also used : Pattern(java.util.regex.Pattern) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) TextListener(org.junit.internal.TextListener) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Result(org.junit.runner.Result) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

TextListener (org.junit.internal.TextListener)15 JUnitCore (org.junit.runner.JUnitCore)12 Result (org.junit.runner.Result)6 RunListener (org.junit.runner.notification.RunListener)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 JUnitSystem (org.junit.internal.JUnitSystem)2 RealSystem (org.junit.internal.RealSystem)2 Description (org.junit.runner.Description)2 Request (org.junit.runner.Request)2 Failure (org.junit.runner.notification.Failure)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 Pattern (java.util.regex.Pattern)1