android - Instrumentation run failed due to 'java.lang.ClassNotFoundException'error while running Unit test through Espresso -


i new in android development coding. have developed 1 basic app mo call through pressing 1 button.

i trying test app through espresso.here code :

app name : phonecall

mainacticity.java code :

package com.test.phonecall;      import android.content.intent;     import android.net.uri;     import android.os.bundle;     import android.support.v7.app.actionbaractivity;     import android.view.menu;     import android.view.menuitem;     import android.view.view;      public class mainactivity extends actionbaractivity {          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_main);           }           @override         public boolean oncreateoptionsmenu(menu menu) {              // inflate menu; adds items action bar if present.             getmenuinflater().inflate(r.menu.main, menu);             return true;         }          @override         public boolean onoptionsitemselected(menuitem item) {             // handle action bar item clicks here. action bar             // automatically handle clicks on home/up button, long             // specify parent activity in androidmanifest.xml.             int id = item.getitemid();             if (id == r.id.action_settings) {                 return true;             }             return super.onoptionsitemselected(item);         }          /**          * placeholder fragment containing simple view.          */           public void onclickfun(view view)         {             try             {                 uri number = uri.parse("tel:" + "xxxxxxxx");                 intent dial = new intent(intent.action_call, number);                 startactivity(dial);              }catch(exception e){              }         }      }  

manifest file:

<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.test.phonecall"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="11"         android:targetsdkversion="19" /> <uses-permission android:name="android.permission.call_phone" />     <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.test.phonecall.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

test project :

package com.test.phonecall.test;  import junit.framework.assert; import android.app.instrumentation; import android.test.activityinstrumentationtestcase2; import android.util.log;  import com.google.android.apps.common.testing.ui.espresso.espresso; import com.google.android.apps.common.testing.ui.espresso.action.viewactions; import com.google.android.apps.common.testing.ui.espresso.matcher.viewmatchers; import com.test.phonecall.mainactivity; import com.test.phonecall.r;  public class testmainactivity extends activityinstrumentationtestcase2<mainactivity> {     private mainactivity activity;     private instrumentation instrumentation;      public testmainactivity(string name) {         super(mainactivity.class);     }      protected void setup() throws exception {         super.setup();          this.activity = (mainactivity) super.getactivity();         this.instrumentation = super.getinstrumentation();     }      protected void teardown() throws exception {         super.teardown();     }      public void testphonecallbtn() {         try {                         log.d("test","in testphonecallbtn");             espresso.onview(viewmatchers.withid(r.id.button1)).perform(viewactions.click());           } catch (exception e) {             log.d("mytestapp", e.getmessage());         }     }      public void testactivitytitleiscorrect()     {         assert.asserttrue(this.activity.gettitle().equals("phonecall"));         log.d("test","in testphonecallbtn");         espresso.onview(viewmatchers.withid(r.id.button1)).perform(viewactions.click());     } } 

manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.test.phonecall.test"     android:versioncode="1"     android:versionname="1.0" >     <uses-sdk     android:minsdkversion="15"     android:targetsdkversion="20" />      <application         android:icon="@drawable/ic_launcher"         android:label="@string/app_name" >         <uses-library android:name="android.test.runner" />     </application>      <instrumentation         android:name="com.google.android.apps.common.testing.testrunner.googleinstrumentationtestrunner"         android:targetpackage="com.test.phonecall"/>  </manifest> 

exception logs :

01-12 06:10:35.569: w/dalvikvm(10800): threadid=1: thread exiting uncaught exception (group=0x415d9d58) 01-12 06:10:35.569: e/androidruntime(10800): fatal exception: main 01-12 06:10:35.569: e/androidruntime(10800): process: com.test.phonecall, pid: 10800 01-12 06:10:35.569: e/androidruntime(10800): java.lang.runtimeexception: unable instantiate instrumentation componentinfo{com.test.phonecall.test/com.google.android.apps.common.testing.testrunner.googleinstrumentationtestrunner}: java.lang.classnotfoundexception: didn't find class "com.google.android.apps.common.testing.testrunner.googleinstrumentationtestrunner" on path: dexpathlist[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.test.phonecall.test-2.apk", zip file "/data/app/com.test.phonecall-2.apk"],nativelibrarydirectories=[/data/app-lib/com.test.phonecall.test-2, /data/app-lib/com.test.phonecall-2, /vendor/lib, /system/lib]] 01-12 06:10:35.569: e/androidruntime(10800):    @ android.app.activitythread.handlebindapplication(activitythread.java:4379) 01-12 06:10:35.569: e/androidruntime(10800):    @ android.app.activitythread.access$1500(activitythread.java:138) 01-12 06:10:35.569: e/androidruntime(10800):    @ android.app.activitythread$h.handlemessage(activitythread.java:1259) 01-12 06:10:35.569: e/androidruntime(10800):    @ android.os.handler.dispatchmessage(handler.java:102) 01-12 06:10:35.569: e/androidruntime(10800):    @ android.os.looper.loop(looper.java:136) 01-12 06:10:35.569: e/androidruntime(10800):    @ android.app.activitythread.main(activitythread.java:5111) 01-12 06:10:35.569: e/androidruntime(10800):    @ java.lang.reflect.method.invokenative(native method) 01-12 06:10:35.569: e/androidruntime(10800):    @ java.lang.reflect.method.invoke(method.java:515) 01-12 06:10:35.569: e/androidruntime(10800):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 01-12 06:10:35.569: e/androidruntime(10800):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:602) 01-12 06:10:35.569: e/androidruntime(10800):    @ dalvik.system.nativestart.main(native method) 01-12 06:10:35.569: e/androidruntime(10800): caused by: java.lang.classnotfoundexception: didn't find class "com.google.android.apps.common.testing.testrunner.googleinstrumentationtestrunner" on path: dexpathlist[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.test.phonecall.test-2.apk", zip file "/data/app/com.test.phonecall-2.apk"],nativelibrarydirectories=[/data/app-lib/com.test.phonecall.test-2, /data/app-lib/com.test.phonecall-2, /vendor/lib, /system/lib]] 01-12 06:10:35.569: e/androidruntime(10800):    @ dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56) 01-12 06:10:35.569: e/androidruntime(10800):    @ java.lang.classloader.loadclass(classloader.java:497) 01-12 06:10:35.569: e/androidruntime(10800):    @ java.lang.classloader.loadclass(classloader.java:457) 01-12 06:10:35.569: e/androidruntime(10800):    @ android.app.activitythread.handlebindapplication(activitythread.java:4376) 01-12 06:10:35.569: e/androidruntime(10800):    ... 10 more 

1.ensure espresso jar in libs folder

enter image description here

2.ensure exported in class path

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -