During build we strive to write well tested code by fully unit testing each component. We believe that it should take just as long to write unit tests for a component as it did to write the actual component if not longer.

A unit test should not just consist of sunny day scenarios but should also include scenarios that cover the boundaries and failures.

Testing doesn’t stop at the unit level. Components should be integration tested to validate that interacting components work as intended. Load and stress testing is also vital to the stability of the application.

When you have a comprehesive testing suite in place you can be confident of making changes without significantly breaking the product. Catching this straight away during development is far better than finding it in production.

@Runner(JUnitRunner.class)
public class CarBuilderTest {

  @Rule
  public ExpectedException expectedException =
      ExpectedException.none();

  @Test
  public void testSettingEngineSize() {
    final Car car = new CarBuilder()
      .withEngineSize(2.0)
      .build();
    assertThat(car.getEngineSize(), equalTo(2.0));
  }

  public void testSettingNegativeEngineSize() {
    expectedException.expect(CarBuilderException.class);
    expectedException.expectMessage("Invalid engine size");
    new CarBuilder().withEngineSize(-2.0).build();
  }

  public void testSettingZeroEngineSize() {
    expectedException.expect(CarBuilderException.class);
    expectedException.expectMessage("Invalid engine size");
    new CarBuilder().withEngineSize(0).build();
  }

  // etc...