Java – Android junit : Method scheme in Not simulated

Android junit : Method scheme in Not simulated… here is a solution to the problem.

Android junit : Method scheme in Not simulated

I’m trying to learn how to do unit testing in Android, but I’m stuck with this particular issue. I searched for previous SO posts but none of them are related to this error. I get this exception:

java.lang.RuntimeException: Method scheme in$Builder not mocked. See for details.

Why does Uri.Builder’s method “scheme” need to be simulated? Thanks!

package com.karljamoralin.popularmovies;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class MovieDBAPITest {

MovieDBAPI movieDBAPI = new MovieDBAPI();

    public void URLValidator() {

    public void test() {
        assertEquals("a", movieDBAPI.test());


package com.karljamoralin.popularmovies;

import android.os.AsyncTask;
import android.util.Log;

public class MovieDBAPI extends AsyncTask<String, Void, Void> {

final String TAG = getClass().getSimpleName();

    protected Void doInBackground(String... params) {

Uri uri = buildUri(params[0]);

Log.v(TAG, uri.toString());

Connect to URL

Get string input

Parse string input

Return M

return null;

    protected void onPostExecute(Void aVoid) {

Uri buildUri(String mode) {

final String SCHEME = "https";
        final String AUTHORITY = "";
        final String PATH1 = "3";
        final String PATH2 = "movie";
        final String API_KEY = "movie";
        final String LANGUAGE = "language";

Uri.Builder uriBuilder = new Uri.Builder();
        uriBuilder.appendQueryParameter(API_KEY, "test");
        uriBuilder.appendQueryParameter(LANGUAGE, "en-US");



String test() {
        return "a";



Yes, tests like the Android SDK suck.
The Uri class is not implemented in the development jar.

My advice is to make wrapper classes for these cases and use them in testing. Other possibilities are to use Robolectric or Android Instrumentation Tests .

Related Problems and Solutions