Open GoogleCodeExporter opened 9 years ago
I did tried earlier with inheriting "TestCase" class like this:
public class TestYCustomBannerAd extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
@UsesMocks({Context.class,WebView.class})
public void testConstructWebView() {
Context mockContext = AndroidMock.createMock(Context.class);
WebView mockWebView = AndroidMock.createMock(WebView.class,mockContext);
assertNotNull("The webView instance is null!!!",mockWebView);
}
}
Here I am hitting following error message:
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.yahoo.yadsdk.ads.test.TestYCustomBannerAd.testConstructWebView(TestYCustomBa
nnerAd.java:30)
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:52
0)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.reflect.InvocationTargetException
at
v22.genmocks.android.webkit.WebViewDelegateSubclass.<init>(WebViewDelegateSubcla
ss.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)
... 15 more
Caused by: java.lang.IllegalStateException: missing behavior definition for the
preceeding method call getResources()
at
org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:30
)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:61)
at $Proxy1.getResources(Native Method)
at
v22.genmocks.android.content.ContextDelegateSubclass.getResources(ContextDelegat
eSubclass.java)
at android.view.ViewConfiguration.get(ViewConfiguration.java:211)
at android.view.View.<init>(View.java:1814)
at android.view.View.<init>(View.java:1856)
at android.view.ViewGroup.<init>(ViewGroup.java:291)
at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:52)
at android.webkit.WebView.<init>(WebView.java:937)
at android.webkit.WebView.<init>(WebView.java:920)
at android.webkit.WebView.<init>(WebView.java:910)
at android.webkit.WebView.<init>(WebView.java:901)
... 19 more
Looks like while creating the mock Webview, it is trying to execute some APIs
on mockContext, which I am not aware. Also, should we go ahead and train
mockContext which returns some object for "getResources()" API , doesn't make
any sense to me and looks awkward.
Is there any way, in which "WebView" can be mocked successfully?
Thanks,
Vaibhav
Original comment by agrvaib...@gmail.com
on 16 Feb 2012 at 5:34
Hello,
If mocking WebView is not supported by android-mock, then I am wondering
why following delegate classes have been added in
android_framework_mocks.jar . Is there any way out to use them?
$ jar tvf libs/android_framework_mocks.jar | grep WebView
456 Tue Jan 24 21:20:26 GMT+05:30 2012
v15/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:20:26 GMT+05:30 2012
v15/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1274 Tue Jan 24 21:20:26 GMT+05:30 2012
v15/genmocks/android/webkit/WebViewClientDelegateInterface.class
2733 Tue Jan 24 21:20:26 GMT+05:30 2012
v15/genmocks/android/webkit/WebViewClientDelegateSubclass.class
15017 Tue Jan 24 21:20:26 GMT+05:30 2012
v15/genmocks/android/webkit/WebViewDelegateInterface.class
41626 Tue Jan 24 21:20:26 GMT+05:30 2012
v15/genmocks/android/webkit/WebViewDelegateSubclass.class
456 Tue Jan 24 21:21:04 GMT+05:30 2012
v16/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:21:04 GMT+05:30 2012
v16/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1274 Tue Jan 24 21:21:04 GMT+05:30 2012
v16/genmocks/android/webkit/WebViewClientDelegateInterface.class
2733 Tue Jan 24 21:21:04 GMT+05:30 2012
v16/genmocks/android/webkit/WebViewClientDelegateSubclass.class
15515 Tue Jan 24 21:21:06 GMT+05:30 2012
v16/genmocks/android/webkit/WebViewDelegateInterface.class
42810 Tue Jan 24 21:21:06 GMT+05:30 2012
v16/genmocks/android/webkit/WebViewDelegateSubclass.class
457 Tue Jan 24 21:21:42 GMT+05:30 2012
v201/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1259 Tue Jan 24 21:21:42 GMT+05:30 2012
v201/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1275 Tue Jan 24 21:21:42 GMT+05:30 2012
v201/genmocks/android/webkit/WebViewClientDelegateInterface.class
2737 Tue Jan 24 21:21:42 GMT+05:30 2012
v201/genmocks/android/webkit/WebViewClientDelegateSubclass.class
15783 Tue Jan 24 21:21:42 GMT+05:30 2012
v201/genmocks/android/webkit/WebViewDelegateInterface.class
43631 Tue Jan 24 21:21:42 GMT+05:30 2012
v201/genmocks/android/webkit/WebViewDelegateSubclass.class
456 Tue Jan 24 21:22:46 GMT+05:30 2012
v21/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:22:46 GMT+05:30 2012
v21/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1274 Tue Jan 24 21:22:46 GMT+05:30 2012
v21/genmocks/android/webkit/WebViewClientDelegateInterface.class
2733 Tue Jan 24 21:22:46 GMT+05:30 2012
v21/genmocks/android/webkit/WebViewClientDelegateSubclass.class
15903 Tue Jan 24 21:22:46 GMT+05:30 2012
v21/genmocks/android/webkit/WebViewDelegateInterface.class
44019 Tue Jan 24 21:22:46 GMT+05:30 2012
v21/genmocks/android/webkit/WebViewDelegateSubclass.class
456 Tue Jan 24 21:23:24 GMT+05:30 2012
v22/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:23:24 GMT+05:30 2012
v22/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1392 Tue Jan 24 21:23:24 GMT+05:30 2012
v22/genmocks/android/webkit/WebViewClientDelegateInterface.class
2921 Tue Jan 24 21:23:24 GMT+05:30 2012
v22/genmocks/android/webkit/WebViewClientDelegateSubclass.class
16210 Tue Jan 24 21:23:24 GMT+05:30 2012
v22/genmocks/android/webkit/WebViewDelegateInterface.class
44872 Tue Jan 24 21:23:24 GMT+05:30 2012
v22/genmocks/android/webkit/WebViewDelegateSubclass.class
457 Tue Jan 24 21:23:58 GMT+05:30 2012
v231/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1259 Tue Jan 24 21:23:58 GMT+05:30 2012
v231/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1393 Tue Jan 24 21:23:58 GMT+05:30 2012
v231/genmocks/android/webkit/WebViewClientDelegateInterface.class
2925 Tue Jan 24 21:23:58 GMT+05:30 2012
v231/genmocks/android/webkit/WebViewClientDelegateSubclass.class
16458 Tue Jan 24 21:23:58 GMT+05:30 2012
v231/genmocks/android/webkit/WebViewDelegateInterface.class
45619 Tue Jan 24 21:23:58 GMT+05:30 2012
v231/genmocks/android/webkit/WebViewDelegateSubclass.class
457 Tue Jan 24 21:25:00 GMT+05:30 2012
v233/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1259 Tue Jan 24 21:25:00 GMT+05:30 2012
v233/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1393 Tue Jan 24 21:25:00 GMT+05:30 2012
v233/genmocks/android/webkit/WebViewClientDelegateInterface.class
2925 Tue Jan 24 21:25:00 GMT+05:30 2012
v233/genmocks/android/webkit/WebViewClientDelegateSubclass.class
16458 Tue Jan 24 21:25:00 GMT+05:30 2012
v233/genmocks/android/webkit/WebViewDelegateInterface.class
45619 Tue Jan 24 21:25:00 GMT+05:30 2012
v233/genmocks/android/webkit/WebViewDelegateSubclass.class
456 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1508 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebViewClientDelegateInterface.class
3107 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebViewClientDelegateSubclass.class
18759 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebViewDelegateInterface.class
52530 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebViewDelegateSubclass.class
2079 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebViewFragmentDelegateInterface.class
5232 Tue Jan 24 21:26:30 GMT+05:30 2012
v30/genmocks/android/webkit/WebViewFragmentDelegateSubclass.class
456 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1625 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebViewClientDelegateInterface.class
3296 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebViewClientDelegateSubclass.class
19133 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebViewDelegateInterface.class
53381 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebViewDelegateSubclass.class
2161 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebViewFragmentDelegateInterface.class
5384 Tue Jan 24 21:27:38 GMT+05:30 2012
v31/genmocks/android/webkit/WebViewFragmentDelegateSubclass.class
456 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1255 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1625 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebViewClientDelegateInterface.class
3296 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebViewClientDelegateSubclass.class
20296 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebViewDelegateInterface.class
56323 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebViewDelegateSubclass.class
2357 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebViewFragmentDelegateInterface.class
5853 Tue Jan 24 21:29:36 GMT+05:30 2012
v40/genmocks/android/webkit/WebViewFragmentDelegateSubclass.class
457 Tue Jan 24 21:30:54 GMT+05:30 2012
v403/genmocks/android/webkit/WebView$WebViewTransportDelegateInterface.class
1259 Tue Jan 24 21:30:54 GMT+05:30 2012
v403/genmocks/android/webkit/WebView$WebViewTransportDelegateSubclass.class
1626 Tue Jan 24 21:30:54 GMT+05:30 2012
v403/genmocks/android/webkit/WebViewClientDelegateInterface.class
3300 Tue Jan 24 21:30:54 GMT+05:30 2012
v403/genmocks/android/webkit/WebViewClientDelegateSubclass.class
20349 Tue Jan 24 21:30:52 GMT+05:30 2012
v403/genmocks/android/webkit/WebViewDelegateInterface.class
56515 Tue Jan 24 21:30:52 GMT+05:30 2012
v403/genmocks/android/webkit/WebViewDelegateSubclass.class
2422 Tue Jan 24 21:30:54 GMT+05:30 2012
v403/genmocks/android/webkit/WebViewFragmentDelegateInterface.class
6057 Tue Jan 24 21:30:52 GMT+05:30 2012
v403/genmocks/android/webkit/WebViewFragmentDelegateSubclass.class
Regards,
Vaibhav
Original comment by agrvaib...@gmail.com
on 15 May 2012 at 5:42
Original issue reported on code.google.com by
agrvaib...@gmail.com
on 1 Feb 2012 at 6:38