Reputation: 7746
I am running android Instrumentation tests to unit test activity and specifically if the WebView has loaded or not code is as follows, but each time i get exception
Running tests Test running started Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.IllegalStateException''. Check device logcat for details Test running failed: Instrumentation run failed due to 'java.lang.IllegalStateException'
There are no Logcat logs , just this message in console , tried on Genymotion as well as device both are on android 5.0.
Code is as 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 is null",testActivity);
}
}
I have tried searching but got no clue why this exception is occurring , please help.
Upvotes: 16
Views: 2002
Reputation: 9
Add a catch statment after the try stetment and give the try statment an exeption. the syntext might be a little off but that should fix your 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 is null",testActivity);
}
}
Upvotes: 1