首页 » 技术分享 » 测试驱动开发(TTD)

测试驱动开发(TTD)

 


        测试应用有很多方法,例如,黑盒测试、白盒测试、迭代测试等,然而,这些方法都是从宏观上描述测试的。为了在技术上保障测试的效果,Kent Beck(也是极限编程创始人)提出了在结果上进行限制的测试方法,也就是在编写程序之前,先确定程序中的变量、控件等元素允许的值。如果在编写程序时,变量、控件中的值与事先确定的值不相符,就说明程序的某处有bug,这种测试方法就是TDD(Test Driver Development,测试驱动开发)。TDD和Opengl ES一样,并不是具体的软件或程序库,只是一套测试框架(Junit),可用于对Android应用程序进行TDD测试。

Android SDK提供的测试框架,该测试框架基于Junit。测试框架不仅可以测试普通的java类(继承AndroidTestcase),也可以测试Android的应用程序组建,如Activity(ActivityInstrumentationTestCase2<>)、ContentProvider(ProviderTestCase<>)、和Service(ServiceTestCase<>)

The testing framework has these key features:

  1. Android test suites are based on JUnit. You can use plain JUnit to test a class that doesn't call the Android API, or Android's JUnit extensions to test Android components. If you're new to Android testing, you can start with general-purpose test case classes such as AndroidTestCase and then go on to use more sophisticated classes.                                                                                          
  2. The Android JUnit extensions provide component-specific test case classes. These classes provide helper methods for creating mock objects and methods that help you control the lifecycle of a component.          
  3. Test suites are contained in test packages that are similar to main application packages, so you don't need to learn a new set of tools or techniques for designing and building tests.                            
  4. The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDEs. These tools get information from the project of the application under test and use this information to automatically create the build files, manifest file, and directory structure for the test package.                                                                                             
  5. The SDK also provides monkeyrunner, an API for testing devices with Python programs, and UI/Application Exerciser Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.


Android测试框架结构图

转载自原文链接, 如需删除请联系管理员。

原文链接:测试驱动开发(TTD),转载请注明来源!

0