mardi 5 décembre 2017

How to test PlacePicker in Android studio

I have an Android Application which uses the Google Places API. I have a button on an Activity which calls the method goPlacePicker and launches the PlacePicker.

My code for launching the places API is:

public void goPlacePicker(View v) {
    // Construct an intent for the place picker
    try {
        PlacePicker.IntentBuilder intentBuilder =
                new PlacePicker.IntentBuilder();
        Intent intent = intentBuilder.build(this);
        // Start the intent by requesting a result,
        // identified by a request code.
        startActivityForResult(intentBuilder.build(this), PLACE_PICKER_REQUEST);

    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_PICKER_REQUEST) {
        if (resultCode == RESULT_OK) {
            Place place = PlacePicker.getPlace(data, this);
            String toastMsg = String.format("You have chosen: %s", place.getName());
            tvPlace.setText("You have chosen: " + place.getName());

            Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
        }
    }
}

As part of this application I have to write some tests to test the code. I am not sure what the best way of testing this is or how I would test it.

Is it possible to write unit tests to test this?

Any help would be appreciated

Aucun commentaire:

Enregistrer un commentaire