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

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).

主站蜘蛛池模板: 巩留县| 中宁县| 古交市| 长沙县| 孝感市| 灵台县| 抚松县| 辽中县| 扎兰屯市| 电白县| 贡觉县| 合江县| 金山区| 涞水县| 普兰店市| 鹤壁市| 海安县| 健康| 信阳市| 湖州市| 和平区| 安丘市| 商南县| 姚安县| 湾仔区| 综艺| 化隆| 儋州市| 张家口市| 栖霞市| 富民县| 中江县| 衢州市| 高安市| 瑞金市| 武清区| 松原市| 宁陕县| 新泰市| 嘉善县| 天气|