Search This Blog

Sunday, August 28, 2011

How to add new java file ?

To add the Java file for the test case class, follow these steps
  1. In Eclipse, open the HelloAndroidTest project if it is not already open.
  2. Within HelloAndroidTest, expand the src/ folder and then find the package icon for com.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.java in the project. This file contains the class HelloAndroidTest, which extends the Activity test case class ActivityInstrumentationTestCase2<T>. You parameterize the class with HelloAndroid, 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 HelloAndroid class, which is not yet imported. To import the class, add the following line just before the current import statement: 
  •  
    import com.example.helloandroid.HelloAndroid;