To add the Java file for the test case class, follow these steps
The New Java Class dialog appears.
3. In the dialog, enter the following:
- In Eclipse, open the HelloAndroidTest project if it is not already open.
- Within HelloAndroidTest, expand the
src/folder and then find the package icon forcom.example.helloandroid.test. Right-click on the package icon and select New > Class:
The New Java Class dialog appears.
3. In the dialog, enter the following:
- Name: "HelloAndroidTest". This becomes the name of your test class.
- Superclass: "
android.test.ActivityInstrumentationTestCase2<HelloAndroid>". The superclass is parameterized by an Activity class name. The dialog should now look like this:
- Do not change any of the other settings. Click Finish.
- You now have a new file
HelloAndroidTest.javain the project. This file contains the classHelloAndroidTest, which extends the Activity test case classActivityInstrumentationTestCase2<T>. You parameterize the class withHelloAndroid, which is the class name of the activity under test. - Open
HelloAndroidTest.java. It should look like this package com.example.helloandroid.test; import android.test.ActivityInstrumentationTestCase2; public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid> { }
- The test case class depends on the
HelloAndroidclass, which is not yet imported. To import the class, add the following line just before the currentimportstatement: import com.example.helloandroid.HelloAndroid;


No comments:
Post a Comment