I don't have much experience on android JUnit test. Here I'm doing a simple test application for JUnit.The application contains two activity when the button pressed in the first activity Intent use to start the second activity. But I'm getting two failures
as junit.framework.AssertionFailedError
. This is the code that I have tried:
public void testLayout(){
buttonId=com.example.androidunittest.R.id.button;
assertNotNull(activity.findViewById(buttonId));
Button view=(Button) activity.findViewById(buttonId);
assertEquals("Incorrect label of the button","Start",view.getText());
}
public void testIntentTriggerViaOnClick(){
buttonId=com.example.androidunittest.R.id.button;
Button view=(Button) activity.findViewById(buttonId);
assertNotNull("Button not allowed to be null",view);
view.performClick();
Intent triggeredIntent=getStartedActivityIntent();
assertNotNull("Intent was null",triggeredIntent);
String data=triggeredIntent.getExtras().getString("URL");
assertEquals("Incorrect data passed via the intent","http://www.google.com", data);
}
The failure line are
assertNotNull("Button not allowed to be null",view);
and assertNotNull(activity.findViewById(buttonId));
according to the JUnit test panel result.
Could anyone please explain me what is happening here? Also how to fix the error in the application code?
I have another question, how to run all test class once in eclipse? What I did is as per this answer , right click on the project -> Run as-> Android JUnit test. But only active class was gave the result.
Any help would be appreciated.