嗨,我在Eclipse中尝试运行单元测试时遇到以下错误:

java.lang.NoClassDefFoundError: android/test/AndroidTestCase
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    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.AndroidTestCase
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 18 more


测试班

public class ResponseUtilTest extends AndroidTestCase {

    private BubbleResponseUtil responseUtil;

    private static final String TAG = ResponseUtilTest.class.getSimpleName();

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        responseUtil = new ResponseUtil();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testGetdata() {

    }

    public void testIsOkMessage() {

    }

    public void testIsRetryMessage() {

    }

    public void testIsMatchedCRC() {

    }

}


非常感谢我使用的是从android dev网站获得的android sdk Eclipse版本。

再次感谢

最佳答案

您需要对设备/仿真器运行AndroidTestCase。我猜您只是将其作为常规的JUnit3 / JUnit4测试用例运行?

关于android - java.lang.NoClassDefFoundError:android/test/AndroidTestCase,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17317456/

10-11 22:16