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

📄 testcase.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
字号:
package momeunit.framework;/** * An abstract class that every test case should extend. The TestCase has a * <code>name</code> property that identifies it. The default value of this * property is is name of {@link TestCase} subclass without 'packages' prefix * (e.g. for class &quot;com.foo.bar.AbcTest&quot; the name of test case will be * &quot;AbcTest&quot;). Name of test case can be set of course using setter * method {@link #setName(String)} or constructor {@link #TestCase(String)}. * TestCase has methods {@link #setUp()} and {@link #tearDown()} for * manipulating fixture (instance variables that can be shared by different * tests). Developers should override them for setting instance variables and * cleaning up after test execution respectively. The code that performs tests * and asserts results should be putted in {@link #test()} method. To run test * case and obtain results call {@link #run()} or {@link #run(TestResult)} * methods. There is a convenience method for creating an empty TestResult * instance {@link #createResult()}. *  * @see Test * @see TestSuite *  * @author Sergio Morozov * @version 1.1.2 */public abstract class TestCase extends Assert implements Test{  /**   * Name of testcase.   *    * @since 1.0   */  private String name;  /**   * No-arg constructor. Sets name of test case to classname of TestCase   * implementation without packages part and ".class" suffix of course.   *    * @since 1.0   */  public TestCase()  {    this(null);  }  /**   * Instantiates TestCase and sets name to the <code>name</code> or classname   * of TestCase implementation without packages part and ".class" suffix of   * course if <code>name</code> is <code>null</code>.   *    * @param name   *          name of test case or null to set name to classname.   * @since 1.0   */  public TestCase(String name)  {    this.setName(name);  }  /**   * Sets name to the <code>name</code> or classname of TestCase   * implementation without packages part and ".class" suffix of course if   * <code>name</code> is <code>null</code>.   *    * @param name   *          name of test case or null to set name to classname.   * @since 1.0   */  public void setName(String name)  {    if (name != null) this.name = name;    else    {      this.name = this.getClass().getName();      this.name = this.name.substring(this.name.lastIndexOf('.') + 1);    }  }  /**   * Returns the name of this test case.   *    * @return name of test case.   * @since 1.0   */  public String getName()  {    return this.name;  }  /**   * Creates a default TestResult object   *    * @return Result newly created TestResult instance.   * @since 1.0   */  protected TestResult createResult()  {    return new TestResult();  }  /**   * Returns 1 as the number of test cases that will be run by this test.   *    * @see momeunit.framework.Test#countTestCases()   *    * @return always 1   * @since 1.0   */  public int countTestCases()  {    return 1;  }  /**   * A convenience method to run this test, collecting the results with a   * default TestResult object.   *    * @return populated with results of test TestResult instance.   * @since 1.0   */  public TestResult run()  {    TestResult result = createResult();    run(result);    return result;  }  public void run(TestResult result)  {    result.run(this);  }  /**   * Runs the bare test sequence.   *    * @exception Throwable   *              if any exception is thrown   * @since 1.0   */  public void runBare() throws Throwable  {    this.setUp();    try    {      this.test();    } finally    {      this.tearDown();    }  }  /**   * Sets up the fixture. This method is called before a test is executed.   *    * @throws Exception   *           if any exception is thrown.   * @since 1.0   */  protected void setUp() throws Exception  {}  /**   * Override to run the test and assert its state.   *    * @exception Throwable   *              if any exception is thrown   * @since 1.0   */  public abstract void test() throws Throwable;  /**   * Tears down the fixture. This method is called after a test is executed.   *    * @throws Exception   *           if any exception is thrown   * @since 1.0   */  protected void tearDown() throws Exception  {}  /**   * Returns a string representation of the test case   *    * @see java.lang.Object#toString()   * @since 1.0   */  public String toString()  {    return this.name;  }}

⌨️ 快捷键说明

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