title: How to test a REST API that uses Retrofit and Dagger2
body: <p>I would like to create a unit test that verifies that the API successfully gets the List of Repos. I would like that the test actually makes the network connection instead of using  a Mock Server. And also, would be good to use RoboElectric for example so the test can run on the JVM.</p>
  
  <p>This to test the Model from the MVP architecture. </p>
  
  <p>I am using a sample project from Mosby, this uses Dagger 2 and Retrofit 1.9.</p>
  
  <pre><code>public interface GithubApi
  {
      @GET("/repositories")
      @Headers("Cache-Control: no-cache")
      public void getRepos(Callback&lt;List&lt;Repo&gt;&gt; callback);
  }
  </code></pre>
  
  <p>This is the module:</p>
  
  <pre><code>@Module()
  public class SampleModule
  {
      @Provides @Singleton public GithubApi providesGithubApi()
      {
          OkHttpClient client = new OkHttpClient();
          client.setCache(new Cache(context.getCacheDir(), 10 * 1024 * 1024));
  
          RestAdapter restAdapter = new RestAdapter.Builder()
              .setClient(new OkClient(client))
              .setEndpoint("https://api.github.com")
              .build();
  
          return restAdapter.create(GithubApi.class);
      }
  }
  </code></pre>