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

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

主站蜘蛛池模板: 河北省| 长垣县| 蒲江县| 江源县| 布拖县| 乌兰县| 逊克县| 上林县| 阿图什市| 玉林市| 榆社县| 郸城县| 临沧市| 称多县| 乃东县| 灵寿县| 临海市| 吉水县| 竹北市| 凤山市| 边坝县| 龙川县| 龙川县| 修武县| 莆田市| 青冈县| 合阳县| 昌吉市| 黄梅县| 白山市| 临沧市| 利津县| 元氏县| 中卫市| 内黄县| 吐鲁番市| 潮安县| 丰原市| 虹口区| 麻栗坡县| 乌兰察布市|