Remove use of deprecated API from test sample code.

Modify tests sample code to use ActivityInstrumentationTestCase2 and its new
constructor.

Change-Id: Idf927b6641c8dfb4aede8cb2bba45de29320bcf5
This commit is contained in:
Brett Chabot
2010-03-18 18:47:53 -07:00
parent 75a73dc9fb
commit 880855ed20
7 changed files with 98 additions and 55 deletions

View File

@@ -16,22 +16,25 @@
package com.example.android.apis;
import android.test.ActivityInstrumentationTestCase;
import android.test.ActivityInstrumentationTestCase2;
/**
* Make sure that the main launcher activity opens up properly, which will be
* verified by {@link ActivityInstrumentationTestCase#testActivityTestCaseSetUpProperly}.
* verified by {@link #testActivityTestCaseSetUpProperly}.
*/
public class ApiDemosTest extends ActivityInstrumentationTestCase<ApiDemos> {
public class ApiDemosTest extends ActivityInstrumentationTestCase2<ApiDemos> {
/**
* The first constructor parameter must refer to the package identifier of the
* package hosting the activity to be launched, which is specified in the AndroidManifest.xml
* file. This is not necessarily the same as the java package name of the class - in fact, in
* some cases it may not match at all.
* Create an {@link ActivityInstrumentationTestCase2} that tests the {@link ApiDemos} activity.
*/
public ApiDemosTest() {
super("com.example.android.apis", ApiDemos.class);
super(ApiDemos.class);
}
/**
* Verifies that activity under test can be launched.
*/
public void testActivityTestCaseSetUpProperly() {
assertNotNull("activity should be launched successfully", getActivity());
}
}

View File

@@ -18,7 +18,7 @@ package com.example.android.apis.view;
import com.example.android.apis.R;
import android.test.ActivityInstrumentationTestCase;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.KeyEvent;
import android.widget.Button;
@@ -42,26 +42,25 @@ import android.widget.Button;
* See {@link com.example.android.apis.AllTests} for documentation on running
* all tests and individual tests in this application.
*/
public class Focus2ActivityTest extends ActivityInstrumentationTestCase<Focus2> {
public class Focus2ActivityTest extends ActivityInstrumentationTestCase2<Focus2> {
private Button mLeftButton;
private Button mCenterButton;
private Button mRightButton;
/**
* The first constructor parameter must refer to the package identifier of the
* package hosting the activity to be launched, which is specified in the AndroidManifest.xml
* file. This is not necessarily the same as the java package name of the class - in fact, in
* some cases it may not match at all.
* Creates an {@link ActivityInstrumentationTestCase2} that tests the {@link Focus2} activity.
*/
public Focus2ActivityTest() {
super("com.example.android.apis", Focus2.class);
super(Focus2.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
final Focus2 a = getActivity();
// ensure a valid handle to the activity has been returned
assertNotNull(a);
mLeftButton = (Button) a.findViewById(R.id.leftButton);
mCenterButton = (Button) a.findViewById(R.id.centerButton);
mRightButton = (Button) a.findViewById(R.id.rightButton);