Issue
Some time ago I created some instrumented tests using ProviderTestCase2. Now I wanted to update my codebase and tried to reactivate my old tests in the current environment.
1) When I update to compileSdkVersion 28 there seems to be no class ProviderTestCase2 any more. Cleaning and building the Project failed. If I go back to version 27 I can successfully build the project.
2) I have a special case where I want to test different variants of an object with a set of tests. So I decided to make use of inheritance and placed the tests in the base class, configuring the objects to be tested by the superclass. This had worked in the past. (Yes, I know about opinions that inheritance in tests is bad, but in this case it is OK ;-) )
Now no tests are executed. Android Studio complains that there is an empty test suite.
Also there are warnings that I have tests with JUnit4 Annotations in a class extending JUnit3. I do not remember that I saw these warnings in the past.
Is this a bug in the Android Libraries? Or where can I find some hints how to solve this problem?
(Using Android Studio 3.2 and the currentmost libraries)
Solution
The ProviderTestCase2 was removed. The ProviderTestRule
should be used instead (from support test library or AndroidX).
See:
- Android Developers Blog: Android Testing Support Library 1.0 is here! (see heading ProviderTestRule) and
- Android Developer Reference: ProviderTestRule
Add the com.android.support.test:rules
dependency, to be able to use the rule.
Here is an example from the reference page:
@Rule
public ProviderTestRule mProviderRule =
new ProviderTestRule.Builder(MyContentProvider.class, MyContentProvider.AUTHORITY).build();
@Test
public void verifyContentProviderContractWorks() {
ContentResolver resolver = mProviderRule.getResolver();
// perform some database (or other) operations
Uri uri = resolver.insert(testUrl, testContentValues);
// perform some assertions on the resulting URI
assertNotNull(uri);
}
Answered By - WebDucer