Most visited

Recently visited

Added in API level 1
Deprecated since API level 24

AndroidTestCase

public class AndroidTestCase
extends TestCase

java.lang.Object
   ↳ junit.framework.Assert
     ↳ junit.framework.TestCase
       ↳ android.test.AndroidTestCase
Known Direct Subclasses


此类在API级别24中已被弃用。
改为使用InstrumentationRegistry 。 新的测试应该使用Android Testing Support Library编写 。

如果您需要访问资源或其他依赖于活动上下文的内容,请将其扩展。

Summary

Fields

protected Context mContext

Public constructors

AndroidTestCase()

Public methods

void assertActivityRequiresPermission(String packageName, String className, String permission)

断言启动给定活动受到特定权限的保护,方法是尝试启动该活动并验证是否抛出了提及其错误消息中的权限的 SecurityException 。

void assertReadingContentUriRequiresPermission(Uri uri, String permission)

断言从uri内容中读取需要通过查询uri获得特别的许可,并确保 SecurityException提及的特定权限。

void assertWritingContentUriRequiresPermission(Uri uri, String permission)

断言写入内容uri需要通过插入到uri中并确保 SecurityException提到特定权限的特定权限。

Context getContext()
void setContext(Context context)
void testAndroidTestCaseSetupProperly()

Protected methods

void scrubClass(Class<?> testCaseClass)

这个函数在tearDown()时间被各种TestCase实现调用,以清除任何类变量。

void setUp()

设置夹具,例如打开网络连接。

void tearDown()

例如,关闭网络连接就可以拆卸灯具。

Inherited methods

From class junit.framework.TestCase
From class junit.framework.Assert
From class java.lang.Object
From interface junit.framework.Test

Fields

mContext

Added in API level 1
Context mContext

Public constructors

AndroidTestCase

Added in API level 1
AndroidTestCase ()

Public methods

assertActivityRequiresPermission

Added in API level 4
void assertActivityRequiresPermission (String packageName, 
                String className, 
                String permission)

声明启动某个给定活动受到特定权限的保护,方法是尝试启动该活动并验证是否抛出了在其错误消息中提及权限的SecurityException 。 请注意,不需要使用工具,因为我们所需要的只是一个安全错误,我们不需要等待活动启动并获取活动的句柄。

Parameters
packageName String: The package name of the activity to launch.
className String: The class of the activity to launch.
permission String: The name of the permission.

assertReadingContentUriRequiresPermission

Added in API level 4
void assertReadingContentUriRequiresPermission (Uri uri, 
                String permission)

断言从uri内容读取需要通过查询uri来获得特定的许可,并确保提及特定的权限 SecurityException 。

Parameters
uri Uri: The uri that requires a permission to query.
permission String: The permission that should be required.

assertWritingContentUriRequiresPermission

Added in API level 4
void assertWritingContentUriRequiresPermission (Uri uri, 
                String permission)

断言写入内容uri需要通过插入uri并确保 SecurityException特定权限才能获得特定许可 SecurityException

Parameters
uri Uri: The uri that requires a permission to query.
permission String: The permission that should be required.

getContext

Added in API level 1
Context getContext ()

Returns
Context

setContext

Added in API level 1
void setContext (Context context)

Parameters
context Context

testAndroidTestCaseSetupProperly

Added in API level 1
void testAndroidTestCaseSetupProperly ()

Protected methods

scrubClass

Added in API level 1
void scrubClass (Class<?> testCaseClass)

这个函数在tearDown()时间被各种TestCase实现调用,以清除任何类变量。 这样可以防止在测试用例创建非静态内部类(因此引用测试用例)并将其提供给其他人保留的情况下发生内存泄漏。

Parameters
testCaseClass Class: The class of the derived TestCase implementation.
Throws
IllegalAccessException

setUp

Added in API level 1
void setUp ()

设置夹具,例如打开网络连接。 在执行测试之前调用此方法。

Throws
异常

tearDown

Added in API level 1
void tearDown ()

例如,关闭网络连接就可以拆卸灯具。 该方法在执行测试后调用。

Throws
异常

Hooray!