java - Android TestRunner fails due to IllegalState exception -


i running android instrumentation tests unit test activity , if webview has loaded or not code follows, each time exception

running tests test running started test failed run completion. reason: 'instrumentation run failed due 'java.lang.illegalstateexception''. check device logcat details test running failed: instrumentation run failed due 'java.lang.illegalstateexception'

there no logcat logs , message in console , tried on genymotion device both on android 5.0.

code follows

public class webviewactivitytest extends activityinstrumentationtestcase2 <webviewactivity> {      webview webview;     webviewactivity testactivity;      public webviewactivitytest()     {         super(webviewactivity.class);     }      @override     protected void setup() throws exception {         super.setup();         testactivity = getactivity();      }      public void testwebview()     {         webview = (webview)testactivity.findviewbyid(r.id.webview);         assertnotnull(webview);     }      public void testpreconditions() {          assertnotnull("webview activity null",testactivity);     } } 

i have tried searching got no clue why exception occurring , please help.

add catch statment after try stetment , give try statment exeption. syntext might little off should fix probleme

public class webviewactivitytest extends activityinstrumentationtestcase2 <webviewactivity> {  webview webview; webviewactivity testactivity;  public webviewactivitytest() {     super(webviewactivity.class); }  @override protected void setup() throws(exeption e) {     super.setup();     testactivity = getactivity();     catch(exeption e)     system.out.println("nope!);  }  public void testwebview() {     webview = (webview)testactivity.findviewbyid(r.id.webview);     assertnotnull(webview); }  public void testpreconditions() {      assertnotnull("webview activity null",testactivity); } 

}


Comments