Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Generate a Mock Intent and return some intent-data from it

I am using ActivityInstrumentationTestCase2 for the unit testing of my application. I have a case where user clicks on a button of Activity 'A' and which in turns open a new Activity 'B' where user will do some work and finally some data is returned to Activity 'A' via setResult(RESULT_OK, intent);

Now, i want to test this via jUnit and want to Mock this workflow so that no user interaction is required. Can someone help me with this.

PS: i dont want to use Robotium for this..i just want to do it via plain ActivityInstrumentationTestCase2 and some Mocking framework.

like image 399
mudit Avatar asked Nov 27 '13 13:11

mudit


1 Answers

Try this code to

// Check the intent which was started
    Intent triggeredIntent = getStartedActivityIntent();
    assertNotNull("Intent was null", triggeredIntent);
    String data = triggeredIntent.getExtras().getString("URL");

//And

@Override 
protected void setUp() throws Exception {
    super.setUp();
    Intent intent = new Intent(getInstrumentation().getTargetContext(),
        MainActivity.class);
    startActivity(intent, null, null);
    activity = getActivity();
  }

For details :: Follow this link

like image 182
Jatin Malwal Avatar answered Sep 19 '22 03:09

Jatin Malwal