CQM
CQM

Reputation: 44230

Android unit test, super deprecated, replacement?

The android unit testing documents say to test with junit like this

public SpinnerActivityTest() {
      super("com.android.example.spinner", SpinnerActivity.class);
} // end of SpinnerActivityTest constructor definition

http://developer.android.com/tools/testing/activity_test.html#InstallCompletedTestApp

Their example uses Android 2.1 though.

My app is using Android 4.2 although is backwards compatible.

What has the super class been replaced with? How should my constructor be written

Upvotes: 3

Views: 3005

Answers (2)

Patrick Lacz
Patrick Lacz

Reputation: 181

The API level 24 recommendations are to use the Testing Support Library. The InstrumentationRegistry.getTargetContext() method is probably what you want if you were using getContext().

Upvotes: 0

HyprGeek
HyprGeek

Reputation: 147

You will need to use the call:

super (SpinnerActivity.class);

It's specified in the Android reference docs.

ActivityInstrumentationTestCase2(String pkg, Class<T> activityClass)
This constructor was deprecated in API level 8. use ActivityInstrumentationTestCase2(Class) instead

Use this instead.

ActivityInstrumentationTestCase2(Class<T> activityClass)
Creates an ActivityInstrumentationTestCase2.

Parameters
activityClass   The activity to test. This must be a class in the instrumentation targetPackage specified in the AndroidManifest.xml

Upvotes: 5

Related Questions