Android "Hell, Testing"

http://androidappdocs.appspot.com/resources/tutorials/testing/helloandroid_test.html

 

I exercised according "hello, Testing" article above, but got the errors:

 

java.lang.NoClassDefFoundError: android/test/ActivityInstrumentationTestCase2

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:634)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)

at java.net.URLClassLoader.access$000(URLClassLoader.java:73)

at java.net.URLClassLoader$1.run(URLClassLoader.java:212)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:205)

at java.lang.ClassLoader.loadClass(ClassLoader.java:321)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)

at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.lang.ClassNotFoundException: android.test.ActivityInstrumentationTestCase2

at java.net.URLClassLoader$1.run(URLClassLoader.java:217)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:205)

at java.lang.ClassLoader.loadClass(ClassLoader.java:321)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)

at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)

... 17 more

My code:
HelloAndroidTest.java
package com.example.helloandroid.test;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
import com.example.helloandroid.HelloAndroid;
public class HelloAndroidTest extends
ActivityInstrumentationTestCase2<HelloAndroid> {
private HelloAndroid mActivity;
private TextView mView;
private String resourceString;
   
    public HelloAndroidTest() {
        super("com.example.helloandroid", HelloAndroid.class);
      }
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mActivity = this.getActivity();
        mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);
        resourceString = mActivity.getString(com.example.helloandroid.R.string.hello);
    }
    
    public void testPreconditions() {
        assertNotNull(mView);
    }
    public void testText() {
        assertEquals(resourceString,(String)mView.getText());
    }
}
How to solve it?

你可能感兴趣的:(Android "Hell, Testing")