title: How to write integration test cases for the two activities in android
body: <p>Actually i am new to test case here i go on with the integration tests for the two activities.</p>
  
  <p>Below code:</p>
  
  <pre><code>public class MainActivityFunctionalTest extends
      ActivityInstrumentationTestCase2&lt;MainActivity&gt; {
  
    private MainActivity activity;
  
    public MainActivityFunctionalTest() {
      super(MainActivity.class);
    }
    @Override
    protected void setUp() throws Exception {
      super.setUp();
      setActivityInitialTouchMode(false);
      activity = getActivity();
    }
  
    public void testStartSecondActivity() throws Exception {
  
  
  
      // add monitor to check for the second activity
      ActivityMonitor monitor =
          getInstrumentation().
            addMonitor(SecondActivity.class.getName(), null, false);
  
      // find button and click it
      Button view = (Button) activity.findViewById(R.id.button1);
  
      // TouchUtils handles the sync with the main thread internally
      TouchUtils.clickView(this, view);
  
      // to click on a click, e.g., in a listview
      // listView.getChildAt(0);
  
      // wait 2 seconds for the start of the activity
      SecondActivity startedActivity = (SecondActivity) monitor
          .waitForActivityWithTimeout(2000);
      assertNotNull(startedActivity);
  
      // search for the textView
      TextView textView = (TextView) startedActivity.findViewById(R.id.resultText);
  
      // check that the TextView is on the screen
      ViewAsserts.assertOnScreen(startedActivity.getWindow().getDecorView(),
          textView);
      // validate the text on the TextView
      assertEquals("Text incorrect", "Started", textView.getText().toString());
  
      // press back and click again
      this.sendKeys(KeyEvent.KEYCODE_BACK);
  
      TouchUtils.clickView(this, view);
    }
  } 
  </code></pre>
  
  <p>Below line which calls SecondActivity gives me null pointer error how can get the value for second activity tried a lot to fix but remains the same.</p>
  
  <p><strong>SecondActivity startedActivity = (SecondActivity) monitor
          .waitForActivityWithTimeout(2000);</strong></p>
  
  <p>If anyone have idea about this please help me.</p>