⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testresult.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
字号:
package momeunit.framework;import java.util.Enumeration;import java.util.Vector;/** * A class that collects the results of execution of tests. *  * @see Test * @see TestCase * @see TestSuite *  * @author Sergio Morozov * @version 1.1.2 */public class TestResult extends Object{  /**   * Collection of tests failures.   *    * @since 1.0   */  protected Vector failures;  /**   * Collection of exceptions (except {@link AssertionFailedError} thrown while   * executing tests.   *    * @since 1.0   */  protected Vector errors;  /**   * Registered test listener.   *    * @since 1.0   */  protected TestListener listener = null;  /**   * Number of tests run.   *    * @since 1.0   */  protected int runTests;  /**   * Stop indicator.   *    * @since 1.0   */  private boolean shouldStop = false;  /**   * Instantiates TestResult.   *    * @since 1.0   */  public TestResult()  {    failures = new Vector();    errors = new Vector();    runTests = 0;    shouldStop = false;  }  /**   * Adds a {@link Throwable} thrown while executing test to the list of errors.   *    * @param test   *          test that throws specified Throwable.   * @param t   *          Throwable to be added to the list of errors.   * @since 1.0   */  public void addError(Test test, Throwable t)  {    errors.addElement(new TestFailure(test, t));    if (this.listener != null) this.listener.addError(test, t);  }  /**   * Adds a failure of test to the list of failures.   *    * @param test   *          test that fails.   * @param t   *          {@link AssertionFailedError} thrown from failed assertion.   * @since 1.0   */  public void addFailure(Test test, AssertionFailedError t)  {    failures.addElement(new TestFailure(test, t));    if (this.listener != null) this.listener.addFailure(test, t);  }  /**   * Registers a TestListener with this TestResult.   *    * @param listener   *          TestListener instance to be registered with this TestResult.   * @since 1.0   */  public synchronized void setListener(TestListener listener)  {    this.listener = listener;  }  /**   * Informs the result that a test was completed. Notifies registered   * TestListener about the end of test.   *    * @param test   *          test that ends.   * @since 1.0   */  public void endTest(Test test)  {    if (this.listener != null) this.listener.endTest(test);  }  /**   * Returns the number of detected errors.   *    * @return number of detected errors.   * @since 1.0   */  public int errorCount()  {    return errors.size();  }  /**   * Returns Enumeration of detected errors.   *    * @return Enumeration of detected errors.   * @since 1.0   */  public Enumeration errors()  {    return errors.elements();  }  /**   * Returns the number of detected failures.   *    * @return number of detected failures.   * @since 1.0   */  public int failureCount()  {    return failures.size();  }  /**   * Returns an Enumeration of detected failures.   *    * @return Enumeration of detected failures.   * @since 1.0   */  public synchronized Enumeration failures()  {    return failures.elements();  }  /**   * Runs specified TestCase.   *    * @param test   *          TestCase instance to be run.   * @since 1.0   */  protected void run(final TestCase test)  {    startTest(test);    try    {      test.runBare();    } catch (AssertionFailedError e)    {      addFailure(test, e);    } catch (Throwable e)    {      addError(test, e);    }    endTest(test);  }  /**   * Returns the number of tests run.   *    * @return number of tests run.   * @since 1.0   */  public synchronized int runCount()  {    return runTests;  }  /**   * Checks whether the test run should stop.   *    * @return true if test run should stop, false otherwise.   * @since 1.0   */  public synchronized boolean shouldStop()  {    return shouldStop;  }  /**   * Informs the result that a test will be started. Notifies registered   * TestListener about the start of test.   *    * @param test   *          test to be run.   * @since 1.0   */  public void startTest(Test test)  {    final int count = test.countTestCases();    synchronized (this)    {      runTests += count;    }    if (this.listener != null) this.listener.startTest(test);  }  /**   * Notifies that the test run should stop.   *    * @since 1.0   */  public synchronized void stop()  {    shouldStop = true;  }  /**   * Checks whether the entire test was successful or not.   *    * @return true if the entire test was successful, false otherwise.   * @since 1.0   */  public boolean wasSuccessful()  {    return failureCount() == 0 && errorCount() == 0;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -