使用 Android 测试框架 [英] Using Android Test Framework

查看:15
本文介绍了使用 Android 测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 提供了各种测试包,例如

Android provides various packages for testing like

AndroidTestCase应用测试用例仪器测试用例ActivityInstrumentationTestCase2 ActivityTestCase

我需要知道如何决定哪个包最适合测试我的应用.此链接中提供了一些信息

I need to know how to decide which package is best suitable for testing my app. Some info is provided in this link

http://developer.android.com/reference/android/test/package-summary.html

但我需要更清楚这一点...

But I need more clarity on this...

推荐答案

TestCase – 普通的旧 JUnit 测试用例.它可以扩展到测试与 Android 框架无关的实用程序类.

TestCase – Plain old JUnit test case. It can be extended to test utility classes that are not tied to the Android framework.

AndroidTestCase – 它扩展了 JUnit 的 TestCase.这是一个打火机测试类相比活动测试案例.它不需要启动一个活动来运行它.它的getContext() 方法允许您获取如果你需要一个注入的上下文.由于您可以从中获得上下文类,你可以膨胀你的 UI 对象测试他们的行为.

AndroidTestCase – It extends JUnit’s TestCase. It’s a lighter testing class compared to ActivityTestCase. It doesn’t need to launch an activity to run it. Its getContext() method allows you to get an injected context if you need one. Since you can get a context from this class, you can inflate your UI objects to test their behaviors.

ActivityInstrumentationTestCase2 – 这是 ActivityInstrumentationTestCase 的较新版本.ActivityInstrumentationTestCase 在 Android SDK 1.5 中已弃用.与 AndroidTestCase 相比,这是一个更重的测试类.它为单个活动提供 UI 和功能测试.您可以通过调用其 getActivity() 方法来获取您正在测试的注入活动.被测试的活动在每次测试前后启动和完成.

ActivityInstrumentationTestCase2 – It’s the newer version of ActivityInstrumentationTestCase. ActivityInstrumentationTestCase is deprecated in Android SDK 1.5. It’s a heavier testing class compared to AndroidTestCase. It provides UI and functional testing for a single activity. You can get an injected activity that you are testing on by calling its getActivity() method. The activity being tested is launched and finished before and after each test.

ActivityUnitTestCase – 它给出被测试的活动是一个孤立的环境.当使用它来测试一个活动,活动不附加到系统.这给你更多控制什么样的环境你希望你的活动是测试中.

ActivityUnitTestCase – It gives the tested activity an isolated environment. When using it to test an activity, the activity is not attached to the system. This gives you more control over what kind of environment that you want your activity to be tested in.

ApplicationTestCase – 它为应用程序类提供测试.可用于测试应用程序的生命周期.

ApplicationTestCase – It provides testing for Application classes. It can be used to test the life cycle of an application.

InstrumentationTestRunner – 运行 Android 测试的运行器案例.

InstrumentationTestRunner – The runner that runs the Android test cases.

我刚刚发现了这个..希望这对其他人有帮助...如果您想了解更多详细信息,例如何时以及如何使用,请参阅 android SDK 中示例目录中的 APIDemos 测试应用程序.

I just found this..Hope this helps for others...If u want more details like when and how to use, see the APIDemos test application in the samples directory within android SDK.

这篇关于使用 Android 测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆