title: How do you override a module/dependency in a unit test with Dagger 2.0?
body: <p>I have a <a href="https://github.com/glombard/hello-dagger2/blob/master/hello-dagger2-simple/app/src/main/java/com/codeblast/hellodagger2/HelloActivity.java" rel="noreferrer">simple Android activity</a> with a single dependency. I inject the dependency into the activity's <code>onCreate</code> like this:</p>
  
  <pre><code>Dagger_HelloComponent.builder()
      .helloModule(new HelloModule(this))
      .build()
      .initialize(this);
  </code></pre>
  
  <p>In my <code>ActivityUnitTestCase</code> I want to override the dependency with a Mockito mock. I assume I need to use a test-specific module which provides the mock, but I can't figure out how to add this module to the object graph.</p>
  
  <p>In Dagger 1.x this is apparently done with <a href="https://stackoverflow.com/questions/25271721/overriding-debug-module-in-tests">something like this</a>:</p>
  
  <pre><code>@Before
  public void setUp() {
    ObjectGraph.create(new TestModule()).inject(this);
  }
  </code></pre>
  
  <p>What's the Dagger 2.0 equivalent of the above?</p>
  
  <p>You can see my project and its unit test <a href="https://github.com/glombard/hello-dagger2/blob/master/hello-dagger2-simple/app/src/androidTest/java/com/codeblast/hellodagger2/HelloActivityTest.java" rel="noreferrer">here on GitHub</a>.</p>