What steps will reproduce the problem?
1. In an ActivityInstrumentationTestCase2, create a mock of a TextView
What is the expected output? What do you see instead?
Expect to get a mock, but get an exception.
I am able to mock other widget classes (ViewFlipper, ImageView etc) but when I
try to create a mock of a TextView I get the following exception at runtime:
java.lang.ExceptionInInitializerError
at
com.google.android.testing.mocking.AndroidMock.getSubclassFor(AndroidMock.java:2
658)
at
com.google.android.testing.mocking.AndroidMock.createMock(AndroidMock.java:188)
at
com.google.android.testing.mocking.AndroidMock.createMock(AndroidMock.java:157)
at
com.myproject.test.album.TestAlbumLoadMessageHandler.setUp(TestAlbumLoadMessageH
andler.java:28)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:52
0)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.reflect.InvocationTargetException
at
v22.genmocks.android.widget.TextViewDelegateSubclass.<init>(TextViewDelegateSubc
lass.java)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at
com.google.android.testing.mocking.AndroidMock.getSubclassFor(AndroidMock.java:2
650)
... 12 more
Caused by: java.lang.NullPointerException
at android.widget.TextView.<init>(TextView.java:331)
at android.widget.TextView.<init>(TextView.java:321)
at android.widget.TextView.<init>(TextView.java:316)
... 16 more
Seems an NPE is being thrown within the TextView constructor. I am creating
the mock as follows:
AndroidMock.createMock(TextView.class, getActivity());
May be an Android API issue, but I have verified that I can call the equivalent
constructor manually:
new TextView(getActivity());
without any problems.
Other mocks:
AndroidMock.createMock(ImageView.class, getActivity());
... appear to work as expected.
Original issue reported on code.google.com by jason.po...@gmail.com on 25 Apr 2011 at 10:06
Original issue reported on code.google.com by
jason.po...@gmail.com
on 25 Apr 2011 at 10:06