Android JUnit测试ClassNotFoundException

Android JUnit测试ClassNotFoundException,第1张

概述我正在尝试设置JUnit来测试我的 android项目活动. Android项目在AVD和设备上都运行正常(还有一些bug,这就是为什么我要添加一些单元测试) 我按照这些网站的步骤(它们或多或少相同,但我仍然检查所有这些只是为了确保我做的一切正确) http://mobile.tutsplus.com/tutorials/android/android-sdk-junit-testing/ htt 我正在尝试设置JUnit来测试我的 android项目活动.

Android项目在AVD和设备上都运行正常(还有一些BUG,这就是为什么我要添加一些单元测试)

我按照这些网站的步骤(它们或多或少相同,但我仍然检查所有这些只是为了确保我做的一切正确)
http://mobile.tutsplus.com/tutorials/android/android-sdk-junit-testing/
http://developer.android.com/tools/testing/testing_eclipse.html

我使用与项目相同的工作空间创建了一个测试项目,并创建了我的第一个测试用例.当我尝试运行测试时,我得到以下内容:

[2012-12-09 19:42:56 – AssassinTest] AndroID Launch!
[2012-12-09 19:42:56 – AssassinTest] adb is running normally.
[2012-12-09 19:42:56 – AssassinTest] Performing androID.test.InstrumentationTestRunner JUnit launch
[2012-12-09 19:42:56 – AssassinTest] automatic Target Mode: Preferred AVD ‘Google_Level10′ is available on emulator ’emulator-5554′
[2012-12-09 19:42:56 – AssassinTest] Uploading AssassinTest.apk onto device ’emulator-5554′
[2012-12-09 19:42:57 – AssassinTest] Installing AssassinTest.apk…
[2012-12-09 19:42:59 – AssassinTest] Success!
[2012-12-09 19:42:59 – AssassinTest] Project dependency found,installing: Assassin
[2012-12-09 19:43:01 – Assassin] Application already deployed. No need to reinstall.
[2012-12-09 19:43:01 – AssassinTest] Launching instrumentation androID.test.InstrumentationTestRunner on device emulator-5554
[2012-12-09 19:43:01 – AssassinTest] Collecting test information
[2012-12-09 19:43:04 – AssassinTest] Test run Failed: Instrumentation run Failed due to ‘java.lang.classNotFoundException’

这是我从LogCat得到的:

12-09 19:43:02.929: E/dalvikvm(1255): Unable to resolve Ludes/assassi/test/InGameActivityTest; annotation class 1912-09 19:43:02.929: D/AndroIDRuntime(1255): Shutting down VM12-09 19:43:02.929: W/dalvikvm(1255): threadID=1: thread exiting with uncaught exception (group=0x40015560)12-09 19:43:02.961: E/AndroIDRuntime(1255): FATAL EXCEPTION: main12-09 19:43:02.961: E/AndroIDRuntime(1255): java.lang.NoClassDefFoundError: org.junit.Test12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.reflect.Method.getDeclaredAnnotations(Native Method)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:262)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:188)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.reflect.AccessibleObject.getAnnotation(AccessibleObject.java:196)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.TestMethod.getAnnotation(TestMethod.java:60)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:39)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:30)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at com.androID.internal.util.Predicates$OrPredicate.apply(Predicates.java:106)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:42)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:31)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at com.androID.internal.util.Predicates$NotPredicate.apply(Predicates.java:122)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.TestSuiteBuilder.satisfIEsAllPredicates(TestSuiteBuilder.java:254)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.app.ActivityThread.handleBindApplication(ActivityThread.java:3246)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.app.ActivityThread.access00(ActivityThread.java:117)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:969)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.os.Handler.dispatchMessage(Handler.java:99)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.os.Looper.loop(Looper.java:130)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at androID.app.ActivityThread.main(ActivityThread.java:3683)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.reflect.Method.invokeNative(Native Method)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.reflect.Method.invoke(Method.java:507)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:597)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at dalvik.system.NativeStart.main(Native Method)12-09 19:43:02.961: E/AndroIDRuntime(1255): Caused by: java.lang.classNotFoundException: org.junit.Test in loader dalvik.system.PathClassLoader[/system/framework/com.Google.androID.maps.jar:/system/framework/androID.test.runner.jar:/data/app/udes.assassin.test-1.apk:/data/app/udes.assassin-2.apk]12-09 19:43:02.961: E/AndroIDRuntime(1255):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.classLoader.loadClass(ClassLoader.java:551)12-09 19:43:02.961: E/AndroIDRuntime(1255):     at java.lang.classLoader.loadClass(ClassLoader.java:511)12-09 19:43:02.961: E/AndroIDRuntime(1255):     ... 25 more

在几个论坛上搜索时,我读到这可能是由于一个糟糕的清单文件引起的,但我没有看到我的错误.

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="udes.assassin.test"androID:versionCode="1"androID:versionname="1.0" ><uses-sdk androID:minSdkVersion="10" /><instrumentation    androID:name="androID.test.InstrumentationTestRunner"    androID:targetPackage="udes.assassin" /><application    androID:icon="@drawable/ic_launcher"    androID:label="@string/app_name" >    <uses-library androID:name="androID.test.runner" /></application></manifest>

最后,这是我唯一的JUnit类中的代码(到目前为止)

package udes.assassin.test;import static org.junit.Assert.*;import org.junit.Before;import org.junit.Test;import udes.assassin.InGameActivity;import androID.test.ActivityInstrumentationTestCase2;public class InGameActivityTest         extends ActivityInstrumentationTestCase2<InGameActivity> {    public InGameActivitytest() {        super("udes.assassin",InGameActivity.class);    }    public InGameActivityTest(Class<InGameActivity> activityClass) {        super(activityClass);    }    @Before    protected voID setUp() throws Exception {        super.setUp();    }    @Test    public voID testSetItemposition() {        fail("Not yet implemented");    }}

谢谢

解决方法 这可能是因为JUnit不在您的类路径中.转到项目 – >属性 – > Java构建路径 – > Order and Export并检查是否取消选中JUnit框. 总结

以上是内存溢出为你收集整理的Android JUnit测试ClassNotFoundException全部内容,希望文章能够帮你解决Android JUnit测试ClassNotFoundException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1134773.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存