Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do integration tests with Robolectric?

I have MainActivity and SubActivity.

MainActivity has a button triggering a startActivityForResult calling SubActivity.

The SubActivy has the responsibility to add a record to a certain repository so that when it calls finish, the MainActivty, in the method onActivityResult, has to call the notifyDataSetChanged on the adapter:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(resultCode == RESULT_OK && requestCode == 1) {
                    adapter.notifyDataSetChanged();
            }
    }

Now, is there a way to test this come and go with Robolectric? Right now I'm able to test the intent called with a click from MainActivity to SubActivity (using Shadow objects), but I can't see no way to trigger the finish on SubActivity (with the new element added to the repository) so I can check that the adapter is showing the new element on MainActivity

I'm new to Roboelectric so I don't if what I want to test is beyond what this framework is about. Should I use Mockito?

like image 854
dierre Avatar asked Nov 27 '25 02:11

dierre


1 Answers

I would have two unit tests for both activities.

The MainActivityTest:

  1. Check that SubActivity intent started
  2. Check that onActivityResult refreshes the list on RESULt_OK

The SubActivityTest:

  1. Adds record to database
  2. Finishes with RESULT_OK

For the entire acceptance tests I would use Robotium or Calabash

like image 62
Eugen Martynov Avatar answered Nov 28 '25 15:11

Eugen Martynov