Most visited

Recently visited

Added in API level 1
Deprecated since API level 3

ProviderTestCase

public abstract class ProviderTestCase
extends InstrumentationTestCase

java.lang.Object
   ↳ junit.framework.Assert
     ↳ junit.framework.TestCase
       ↳ android.test.InstrumentationTestCase
         ↳ android.test.ProviderTestCase<T extends android.content.ContentProvider>


此类在API级别3中已弃用。
这个类扩展了InstrumentationTestCase,但应该扩展AndroidTestCase。 改为使用ProviderTestCase2来解决这个问题。

如果您想用 InstrumentationTestCase测试单个内容提供商, InstrumentationTestCase提供 setUp()tearDown()一些锅炉板。

Summary

Public constructors

ProviderTestCase(Class<T> providerClass, String providerAuthority)

Public methods

MockContentResolver getMockContentResolver()
IsolatedContext getMockContext()
T getProvider()
static <T extends ContentProvider> ContentResolver newResolverWithContentProviderFromSql(Context targetContext, Class<T> providerClass, String authority, String databaseName, int databaseVersion, String sql)

Protected methods

void setUp()

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

void tearDown()

放弃测试夹具的环境。

Inherited methods

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

Public constructors

ProviderTestCase

Added in API level 1
ProviderTestCase (Class<T> providerClass, 
                String providerAuthority)

Parameters
providerClass Class
providerAuthority String

Public methods

getMockContentResolver

Added in API level 1
MockContentResolver getMockContentResolver ()

Returns
MockContentResolver

getMockContext

Added in API level 1
IsolatedContext getMockContext ()

Returns
IsolatedContext

getProvider

Added in API level 1
T getProvider ()

Returns
T

newResolverWithContentProviderFromSql

Added in API level 1
ContentResolver newResolverWithContentProviderFromSql (Context targetContext, 
                Class<T> providerClass, 
                String authority, 
                String databaseName, 
                int databaseVersion, 
                String sql)

Parameters
targetContext Context
providerClass Class
authority String
databaseName String
databaseVersion int
sql String
Returns
ContentResolver
Throws
IllegalAccessException
InstantiationException

Protected methods

setUp

Added in API level 1
void setUp ()

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

Throws
异常

tearDown

Added in API level 1
void tearDown ()

放弃测试夹具的环境。

呼吁 shutdown()ContentProvider由mProvider表示。

Throws
异常

Hooray!