TypeNotPresentException when running test

瀏覽次數:249 次
跳到第一則未讀訊息

Mike Liu

未讀,
2010年11月12日 凌晨4:22:572010/11/12
收件者:Android Mock Discussion
Hello,

Trying out Android Mock. I am getting a RuntimeException when running
tests using ActivityInstrumentationTestCase2. The mocks are generated
(I see a DelegateInterface and DelegateSubclass for the mocked class)
and Android Mock log seems ok, but there's an exception complaining it
can't find the mocked class in question.

Running this with Eclipse, and in the pdf instructions, I didn't see
what I had to do with the AndroidMockRuntime jar. Maybe something
there? Any ideas?

Thanks,
Mike

stack trace below:

java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder
$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:
239)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:
520)
at android.app.Instrumentation
$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.TypeNotPresentException: Type
com.womobo.mokka.providers.RegProvider not present
at java.lang.reflect.Method.getDeclaredAnnotations(Native Method)
at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:248)
at
java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:
199)
at
java.lang.reflect.AccessibleObject.getAnnotation(AccessibleObject.java:
207)
at android.test.suitebuilder.TestMethod.getAnnotation(TestMethod.java:
60)
at
android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:
39)
at
android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnnotation.java:
30)
at com.android.internal.util.Predicates
$OrPredicate.apply(Predicates.java:106)
at
android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:
42)
at
android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java:
31)
at com.android.internal.util.Predicates
$NotPredicate.apply(Predicates.java:122)
at
android.test.suitebuilder.TestSuiteBuilder.satisfiesAllPredicates(TestSuiteBuilder.java:
254)
at
android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:
184)
at
android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:
373)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:
4218)
at android.app.ActivityThread.access$3000(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Stephen Woodward

未讀,
2010年11月12日 凌晨4:37:462010/11/12
收件者:androi...@googlegroups.com

Hi Mike,

I'm not at a computer at the moment but I believe that you hit an android test apk gotcha.

Referenced libraries in your main apk are not visible to your test apk. Add the jar file containing com.womobo.mokka.providers.RegProvider to the test apk's referenced libraries and try again.

Let me know how it goes and if no luck I'll have a look later when I'm near a computer.

Thanks,

Steve

Mike Liu

未讀,
2010年11月12日 凌晨4:49:202010/11/12
收件者:Android Mock Discussion
Huh, that's strange. This class is in the main project being tested
(not a library class). I have the test project referencing the main
project. Is that what you meant?

I also get a bunch of warning in the console when compiling (I think
these came after I added android mock): warning: Ignoring InnerClasses
attribute for an anonymous inner class that doesn't come with an
associated EnclosingMethod attribute. (This class was probably
produced by a broken compiler.)

Thanks for the prompt response

Mike

On Nov 12, 5:37 pm, Stephen Woodward <sd.woodwar...@googlemail.com>
wrote:
> Hi Mike,
>
> I'm not at a computer at the moment but I believe that you hit an android
> test apk gotcha.
>
> Referenced libraries in your main apk are not visible to your test apk. Add
> the jar file containing com.womobo.mokka.providers.RegProvider to the test
> apk's referenced libraries and try again.
>
> Let me know how it goes and if no luck I'll have a look later when I'm near
> a computer.
>
> Thanks,
>
> Steve
> android.test.suitebuilder.annotation.HasMethodAnnotation.apply(HasMethodAnn otation.java:> 30)
> > at com.android.internal.util.Predicates
> > $OrPredicate.apply(Predicates.java:106)
> > at
>
> android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java :> 42)
> > at
>
> android.test.suitebuilder.annotation.HasAnnotation.apply(HasAnnotation.java :> 31)
> > at com.android.internal.util.Predicates
> > $NotPredicate.apply(Predicates.java:122)
> > at
>
> android.test.suitebuilder.TestSuiteBuilder.satisfiesAllPredicates(TestSuite Builder.java:> 254)

Mike Liu

未讀,
2010年11月12日 清晨5:02:202010/11/12
收件者:Android Mock Discussion
Stephen,

All is well. Your referenced library clue got me hunting, and it turns
out I did package refactoring but left out android:targetPackage in
the instrumentation manifest.

Thanks for your help,
Mike
回覆所有人
回覆作者
轉寄
0 則新訊息