当前位置: 首页>>代码示例>>Java>>正文


Java TestFailure类代码示例

本文整理汇总了Java中junit.framework.TestFailure的典型用法代码示例。如果您正苦于以下问题:Java TestFailure类的具体用法?Java TestFailure怎么用?Java TestFailure使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TestFailure类属于junit.framework包,在下文中一共展示了TestFailure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRuntimeExceptionsAlsoGenerateLog

import junit.framework.TestFailure; //导入依赖的package包/类
public void testRuntimeExceptionsAlsoGenerateLog() throws Exception {
    if (throwIt != null) {
        Logger.getLogger("").info("Ahoj");
        throw throwIt;
    }
    
    FlowControlTest l = new FlowControlTest("testRuntimeExceptionsAlsoGenerateLog");
    l.throwIt = new NullPointerException();
    TestResult res = l.run();
    assertEquals("No failures", 0, res.failureCount());
    assertEquals("One error", 1, res.errorCount());
    
    Object o = res.errors().nextElement();
    TestFailure f = (TestFailure)o;
    
    if (f.exceptionMessage() == null || f.exceptionMessage().indexOf("Ahoj") == -1) {
        fail("Logged messages shall be in exception message: " + f.exceptionMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:FlowControlTest.java

示例2: testThatTheTimeOutStillPrintsTheWarning

import junit.framework.TestFailure; //导入依赖的package包/类
public void testThatTheTimeOutStillPrintsTheWarning() throws Exception {
    TimeOutHasToPrintLogTest t = new TimeOutHasToPrintLogTest("printAhojAndTimeOut");
    
    CharSequence seq = Log.enable(LOG.getName(), Level.FINE);
    
    TestResult res = t.run();
    
    assertEquals("One test has been run", 1, res.runCount());
    
    String s = seq.toString();
    
    if (s.indexOf("Ahoj") == -1) {
        fail("Ahoj has to be logged:\n" + s);
    }
    
    assertEquals("No error", 0, res.errorCount());
    assertEquals("One failure", 1, res.failureCount());
    
    TestFailure f = (TestFailure)res.failures().nextElement();
    s = f.exceptionMessage();
    if (s.indexOf("Ahoj") == -1) {
        fail("Ahoj has to be part of the message:\n" + s);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:TimeOutHasToPrintLogTest.java

示例3: testThreadDumpPrinted

import junit.framework.TestFailure; //导入依赖的package包/类
public void testThreadDumpPrinted() throws Exception {
    TimeOutHasToPrintLogTest t = new TimeOutHasToPrintLogTest("justTimeOutInOneOfMyMethods");
    
    TestResult res = t.run();
    
    assertEquals("One test has been run", 1, res.runCount());
    TestFailure failure = (TestFailure)res.failures().nextElement();
    String s = failure.exceptionMessage();

    if (s.indexOf("justTimeOutInOneOfMyMethods") == -1) {
        fail("There should be thread dump reported in case of timeout:\n" + s);
    }
    
    assertEquals("No error", 0, res.errorCount());
    assertEquals("One failure", 1, res.failureCount());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TimeOutHasToPrintLogTest.java

示例4: testMyExceptionIsWrappedWithLogMsg

import junit.framework.TestFailure; //导入依赖的package包/类
public void testMyExceptionIsWrappedWithLogMsg() throws Exception {
    LoggingTest inner = new LoggingTest("throwMyThrowable");
    
    class MyEx extends Exception {
    }
    
    inner.toThrow = new MyEx();
    
    TestResult res = inner.run();
    assertEquals("One error", 1, res.errorCount());
    assertEquals("No failure", 0, res.failureCount());
    
    TestFailure f = (TestFailure)res.errors().nextElement();
    
    if (f.exceptionMessage() == null || f.exceptionMessage().indexOf("Going to throw") == -1) {
        fail("There should be output of the log:\n" + f.exceptionMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:LoggingTest.java

示例5: testMyExceptionWithStackTrace

import junit.framework.TestFailure; //导入依赖的package包/类
public void testMyExceptionWithStackTrace() throws Exception {
    LoggingTest inner = new LoggingTest("throwMyThrowable");
    
    class MyEx extends Exception {
    }
    
    inner.toThrow = new MyEx();
    inner.toMsg = new MyEx();
    
    TestResult res = inner.run();
    assertEquals("One error", 1, res.errorCount());
    assertEquals("No failure", 0, res.failureCount());
    
    TestFailure f = (TestFailure)res.errors().nextElement();
    
    if (
        f.exceptionMessage() == null || 
        f.exceptionMessage().indexOf("Going to throw") == -1 ||
        f.exceptionMessage().indexOf("testMyExceptionWithStackTrace") == -1
   ) {
        fail("There should be output of the log:\n" + f.exceptionMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:LoggingTest.java

示例6: testRuntimeExceptionsAlsoGenerateLog

import junit.framework.TestFailure; //导入依赖的package包/类
public void testRuntimeExceptionsAlsoGenerateLog() throws Exception {
    if (throwIt != null) {
        Logger.getLogger("global").info("Ahoj");
        throw throwIt;
    }
    
    LoggingControlTest l = new LoggingControlTest("testRuntimeExceptionsAlsoGenerateLog");
    l.throwIt = new NullPointerException();
    TestResult res = l.run();
    assertEquals("No failures", 0, res.failureCount());
    assertEquals("One error", 1, res.errorCount());
    
    Object o = res.errors().nextElement();
    TestFailure f = (TestFailure)o;
    
    if (f.exceptionMessage() == null || f.exceptionMessage().indexOf("Ahoj") == -1) {
        fail("Logged messages shall be in exception message: " + f.exceptionMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:LoggingControlTest.java

示例7: displayProblems

import junit.framework.TestFailure; //导入依赖的package包/类
private void displayProblems( PrintWriter writer, String kind, int count, Enumeration enumeration ) {
    if (count != 0) {
        displayProblemTitle( writer, getFormatted( count, kind ) );
        Enumeration e = enumeration;
        for (int i = 1; e.hasMoreElements(); i++) {
            TestFailure failure = (TestFailure) e.nextElement();
            displayProblemDetailHeader( writer, i, failure.failedTest().toString() );
            if (failure.thrownException() instanceof AssertionFailedError) {
                displayProblemDetail( writer, failure.thrownException().getMessage() );
            } else {
                displayProblemDetail( writer, BaseTestRunner.getFilteredTrace( failure.thrownException() ) );
            }
            displayProblemDetailFooter( writer );
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:JUnitServlet.java

示例8: displayResults

import junit.framework.TestFailure; //导入依赖的package包/类
private void displayResults( PrintWriter writer, String failureNodeName, Enumeration resultsEnumeration ) {
    for (Enumeration e = resultsEnumeration; e.hasMoreElements();) {
        TestFailure failure = (TestFailure) e.nextElement();
        writer.println( "  <testcase name=" + asAttribute( failure.failedTest().toString() ) + ">" );
        writer.print( "    <" + failureNodeName + " type=" + asAttribute( failure.thrownException().getClass().getName() ) +
                                              " message=" + asAttribute( failure.exceptionMessage() ) );
        if (!displayException( failure )) {
            writer.println( "/>" );
        } else {
            writer.println( ">" );
            writer.print( sgmlEscape( BaseTestRunner.getFilteredTrace( failure.thrownException() ) ) );
            writer.println( "    </" + failureNodeName + ">" );
        }
        writer.println( "  </testcase>" );
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:JUnitServlet.java

示例9: populateFailures

import junit.framework.TestFailure; //导入依赖的package包/类
/**
 * Populate the list of failures in each of the suites.
 */
private void populateFailures(boolean errors, Enumeration<TestFailure> failures) {
    while (failures.hasMoreElements()) {
        TestFailure failure = failures.nextElement();
        TestId test = new TestId(failure.failedTest());
        Suite suite = suites.get(test.className);

        if (suite == null) {
            throw new IllegalStateException( "received a failure for a "
                    + "test that wasn't in the original test suite!");
        }

        if (errors) {
            suite.errors.put(test, failure);
        } else {
            suite.failures.put(test, failure);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:22,代码来源:XmlReportPrinter.java

示例10: outputErrorInfo

import junit.framework.TestFailure; //导入依赖的package包/类
protected static void outputErrorInfo(Enumeration e, boolean quiet) {
    while (e.hasMoreElements()) {
        TestFailure tf = (TestFailure) e.nextElement();
        if (! quiet) {
            System.out.println(tf.trace());
            Throwable t = tf.thrownException().getCause();
            while (t != null) {
                t.printStackTrace();
                t = t.getCause();
            }
        } else {
            System.out.println(tf.toString());
            System.out.println("run without -quiet for more information");
        }
    }
}
 
开发者ID:Twixer,项目名称:mondrian-3.1.5,代码行数:17,代码来源:SimpleTestRunner.java

示例11: testFailOnMessage

import junit.framework.TestFailure; //导入依赖的package包/类
public void testFailOnMessage() {
    System.setProperty("generate.msg", "true");
    System.setProperty("generate.exc", "false");

    Test instance =
        NbModuleSuite.createConfiguration(NbModuleSuiteException.class).
        gui(false).
        failOnMessage(Level.WARNING)
    .suite();
    TestResult r = junit.textui.TestRunner.run(instance);
    assertEquals("One failure", 1, r.failureCount());
    assertEquals("No errors", 0, r.errorCount());
    TestFailure f = r.failures().nextElement();
    assertEquals("Failure name", "testGenerateMsgOrException", ((TestCase)f.failedTest()).getName());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:NbModuleSuiteExceptionTest.java

示例12: testFailOnException

import junit.framework.TestFailure; //导入依赖的package包/类
public void testFailOnException() {
    System.setProperty("generate.msg", "false");
    System.setProperty("generate.exc", "true");

    Test instance =
        NbModuleSuite.createConfiguration(NbModuleSuiteException.class).
        gui(false).
        failOnException(Level.INFO)
    .suite();
    TestResult r = junit.textui.TestRunner.run(instance);
    assertEquals("One failure", 1, r.failureCount());
    assertEquals("No errors", 0, r.errorCount());
    TestFailure f = r.failures().nextElement();
    assertEquals("Failure name", "testGenerateMsgOrException", ((TestCase)f.failedTest()).getName());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:NbModuleSuiteExceptionTest.java

示例13: run

import junit.framework.TestFailure; //导入依赖的package包/类
public void run(TestResult result) {
    if (!canRun()) {
        return;
    }
    this.main = Thread.currentThread();
    
    TestResult mine = new TestResult();
    result.startTest(this);
    super.run(mine);
    
    if (mine.errorCount() != 0) {
        Enumeration en = mine.errors();
        while(en.hasMoreElements()) {
            TestFailure f = (TestFailure)en.nextElement();
            result.addError(this, f.thrownException());
        }
        return;
    }
    if (expectedResult != (mine.failureCount() == 0)) {
        result.addFailure(this, 
            new AssertionFailedError(
                "expectedResult: " + expectedResult + "failureCount: " + mine.failureCount() + " for " + getName()
            )
        );
        return;
    }
    
    result.endTest(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:TimeOutTest.java

示例14: testIOExceptionIsWrappedWithLogMsg

import junit.framework.TestFailure; //导入依赖的package包/类
public void testIOExceptionIsWrappedWithLogMsg() throws Exception {
    
    LoggingTest inner = new LoggingTest("throwIOThrowable");
    inner.toThrow = new IOException("Ahoj");
    
    TestResult res = inner.run();
    assertEquals("One error", 1, res.errorCount());
    assertEquals("No failure", 0, res.failureCount());
    
    TestFailure f = (TestFailure)res.errors().nextElement();
    
    if (f.exceptionMessage().indexOf("Going to throw") == -1) {
        fail("There should be output of the log:\n" + f.exceptionMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:LoggingTest.java

示例15: main

import junit.framework.TestFailure; //导入依赖的package包/类
public static void main(String [] args) {
    TestResult tr = new TestResult();
    Test t = suite();
    t.run(tr);
    System.out.println(tr.errorCount());
    Enumeration e = tr.failures();
    while (e.hasMoreElements()) {
        ((TestFailure)e.nextElement ()).thrownException().printStackTrace();
    }
    System.out.println(tr.failureCount());
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:12,代码来源:NullableUniqueConstraintTest.java


注:本文中的junit.framework.TestFailure类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。