title: Repeating code in JUnit tests
body: <p>Is it "bad" to duplicate code in the testclass? As you see I add drivingrecords to the drivinglog to have something to test on in multiple methods. Is it better to extract this to a private helper method or is it better for clarity to keep it like it is? What do you do in such cases?</p>
  
  <pre><code>@Test
  public void shouldRemoveAllDrivingRecords() {
      Duration duration1 = new Duration(1, 30, 45);
      Duration duration2 = new Duration(2, 50, 12);
  
      DrivingRecord drivingRecord1 = new DrivingRecord(230.0, duration1, "This was a long trip");
      DrivingRecord drivingRecord2 = new DrivingRecord(300.0, duration2, "This trip is even longer.");
  
      drivingLog.addDrivingRecord(drivingRecord1);
      drivingLog.addDrivingRecord(drivingRecord2);
  
      drivingLog.removeAllDrivingLogs();
  
      assertEquals(0, drivingLog.numberOfDrivingRecords());
  }
  
  @Test
  public void shouldSumTheDistanceDriven() {
      Duration duration1 = new Duration(1, 30, 45);
      Duration duration2 = new Duration(2, 50, 12);
  
      DrivingRecord drivingRecord1 = new DrivingRecord(230.0, duration1, "This was a long trip");
      DrivingRecord drivingRecord2 = new DrivingRecord(300.0, duration2, "This trip is even longer.");
  
      drivingLog.addDrivingRecord(drivingRecord1);
      drivingLog.addDrivingRecord(drivingRecord2);
  
      double expectedDistanceDriven = drivingRecord1.getDistance() + drivingRecord2.getDistance();
      double totalDistanceDriven = drivingLog.getDistanceDriven();
  
      assertEquals(expectedDistanceDriven, totalDistanceDriven, 0.1);
  }
  </code></pre>