官术网_书友最值得收藏!

The TestCase base class

This is the base class of all other test cases in the JUnit framework. It implements the basic methods that we were analyzing in the previous examples (setUp()). The TestCase class also implements the junit.framework.Test interface, meaning it can be run as a JUnit test.

Your Android test cases should always extend TestCase or one of its descendants.

The default constructor

All test cases require a default constructor because, sometimes, depending on the test runner used, this is the only constructor that is invoked, and is also used for serialization.

According to the documentation, this method is not intended to be used by "mere mortals" without calling setName(String name).

Therefore, to appease the Gods, a common pattern is to use a default test case name in this constructor and invoke the given name constructor afterwards:

public class MyTestCase extends TestCase {
 public MyTestCase() {
 this("MyTestCase Default Name");
 }

   public MyTestCase(String name) {
      super(name);
   }
}

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

The given name constructor

This constructor takes a name as an argument to label the test case. It will appear in test reports and would be of much help when you try to identify where failed tests have come from.

The setName() method

There are some classes that extend TestCase that don't provide a given name constructor. In such cases, the only alternative is to call setName(String name).

主站蜘蛛池模板: 海城市| 临武县| 克拉玛依市| 内黄县| 开封县| 黄浦区| 军事| 墨玉县| 玉环县| 涞水县| 阿克陶县| 石屏县| 南乐县| 文水县| 灵台县| 临沭县| 游戏| 万源市| 双城市| 瑞丽市| 拜泉县| 彭泽县| 自贡市| 郯城县| 鹤峰县| 合作市| 庄河市| 永吉县| 高唐县| 仁寿县| 亚东县| 宝坻区| 正定县| 观塘区| 金阳县| 嘉黎县| 平乐县| 楚雄市| 固安县| 哈尔滨市| 冀州市|