title: Mocking single methods in Go
body: <p>In Go, how can I mock an interface without having to implement every method? Let's say I have a <code>Car</code> interface and a <code>Corolla</code> struct that implements that interface:</p>
  
  <pre><code>type Car interface {
      changeTire()
      startEngine()
      ....
      refuel()
  }
  
  type Corolla struct {
      ...
  }
  
  func (c Corolla) changeTire() {...}
  
  func (c Corolla) startEngine() {...}
  
  func (c Corolla) refuel() {...}
  </code></pre>
  
  <p>Let's say I also have a <code>Garage</code> struct that depends on <code>Car</code>:</p>
  
  <pre><code>type Garage struct {
      MyCar Car
  }
  
  func (g Garage) PrepareCarToDrive() {
      g.MyCar.changeTire()
      g.MyCar.refuel()
      g.MyCar.startEngine()
  }
  </code></pre>
  
  <p>And I want to test <code>Garage</code>, so I create a <code>MockCar</code> that implements <code>Car</code></p>
  
  <pre><code>type MockCar struct {
      ...
  }
  
  func (c MockCar) changeTire() {...}
  
  func (c MockCar) startEngine() {...}
  
  func (c MockCar) refuel() {...}
  </code></pre>
  
  <p>Now I have tests that test  <code>PrepareCarToDrive</code> and I use the <code>MockCar</code>:</p>
  
  <pre><code>func TestGarage_PrepareCarToDrive_DoesSomething(t *testing.T) {
      mockCar := MockCar{}
      garageUnderTest := Garage{}
      garageUnderTest.MyCar = mockCar
  
      // some other setup
  
      // when Garage calls mockCar.changeTire(), should do X
      ...
  }
  
  func TestGarage_PrepareCarToDrive_DoesSomethingElse(t *testing.T) {
      mockCar := MockCar{}
      garageUnderTest := Garage{}
      garageUnderTest.MyCar = mockCar
  
      // some other setup 
      // when Garage calls mockCar.changeTire(), should do Y
      ...
  }
  </code></pre>
  
  <p>My question is, how can I have <code>mockCar</code> do different things each test? I know that I can create a different mock implementation of <code>Car</code> for each test. But this will get out of hand really quickly as I add more methods to <code>Car</code>.</p>
  
  <p>I'm coming from a Java background so I'm looking for something like Mockito that will let me mock just the methods I need for each test.</p>
  
  <p>What is the best way to do this in Go? Or am I missing something more fundamental?</p>