我想在我的Android項目中爲某些網絡類使用JUNIT。我正在使用已包含在android中的Apache HttpClient。但是當我運行我的junit測試時,它遇到了一個異常。我將所有的lib文件都包含在Junit-Testrunner中。但顯然這是不夠的,因爲沒有找到HttpClient。有些人知道我做錯了什麼嗎?如何在JUnit測試用例中使用Android-Libs?
這裏是例外
java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
at de.srs.android.pdixuploader.network.test.ClientAppTest.testCheckLogin(ClientAppTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
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)
產生的原因:在java的在java.net.URLClassLoader的$ 1.run(來源不明)org.apache.http.client.HttpClient :拋出java.lang.ClassNotFoundException .net.URLClassLoader $ 1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher $ AppClassLoader.loadClass(未知來源) at java .lang.ClassLoader.loadClass(來源不明) ...... 19多個