JUnit Android: Test that a button opens an Activity

363 views Asked by At

I am trying to use Junit testing to test whether an Android UIButton properly opens the activity it is intended to run. I am seeing a common theme of using the 'ActivityMonitor' class, but I can't find anything that works. Using another post, I found an example similar to the code below. However, I have errors such as getInstrumentation(). Someone suggested that its due to the lack of the use of Fragments(which is not in my app. Please help!

 @Test
    public void Bookmark() throws Exception {
        final Button mButton = (Button)mActivity.findViewById(R.id.bHome3);
        ActivityMonitor activityMonitor = getInstrumentation().addMonitor(/*class information*/);

        String resourceString;
        final Bookmarks mActivity;

        mActivity = Bookmarks.class.newInstance();


            mActivity.runOnUiThread(
                    new Runnable() {
                        public void run() {
                            mButton.performClick();
                            nextActivity =  getActivity();
                            assertEquals(nextActivity, Question.class);
                        }
                    }
            );



        }
    }
0

There are 0 answers