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

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

主站蜘蛛池模板: 黄大仙区| 福泉市| 新安县| 始兴县| 宝应县| 固阳县| 博野县| 商水县| 青浦区| 策勒县| 阳江市| 三明市| 苏尼特左旗| 金坛市| 宝鸡市| 永修县| 青浦区| 开阳县| 濮阳县| 阜城县| 汝州市| 京山县| 瓦房店市| 福泉市| 车致| 长乐市| 永福县| 新营市| 广饶县| 汶川县| 黄龙县| 怀安县| 安平县| 吉木萨尔县| 禹州市| 南丰县| 上饶县| 水城县| 白银市| 佛学| 南充市|