In this four-part series, I aim to de-mystify what each form of Microservice testing really is. For too many years I’ve scoured articles using greatly oversimplified examples and confusing test terminology. Here, I’ll provide actual Microservice projects I’ve created on Github. They’re designed to look very similar to what you’ll see across companies but still simplified for easy understanding and extensibility.

With these, we’ll show how to build confidence in your product via Automation Testing. Confidence that each part of the application is functioning correctly, that those parts integrate together to form a cohesive whole, and that each application itself integrates with one another to form your Microservice architecture.

Why Unit Test?

How to Unit Test

Exercise

@Test
public void getVehicles_IncludingLexusBrand_ReturnsNoLexus() {
    
}
@Test
public void getVehicles_IncludingLexusBrand_ReturnsNoLexus() {
    List<Vehicle> dbVehicles = new ArrayList<>();
    Vehicle vehicle1 = new Vehicle();
    vehicle1.setId("dbb0c2c3-997c-465b-bb06-b2efb7dad2f7");
    vehicle1.setBrand("Dodge");
    vehicle1.setModel("Charger");
    vehicle1.setImageUrl("https://images.com/dodge-charger.jpg");

    Vehicle vehicle2 = new Vehicle();
    vehicle2.setId("acc0c2c3-997c-465b-bb06-b2efb7dad2f7");
    vehicle2.setBrand("Lexus");
    vehicle2.setModel("IS-250");
    vehicle2.setImageUrl("https://images.com/lexus-250.jpg");

    dbVehicles.add(vehicle1);
    dbVehicles.add(vehicle2);

    when(repository.findAll()).thenReturn(dbVehicles);

    List<Vehicle> vehicles = vehicleService.getVehicles();

    // Only the Dodge should be returned
    Assert.assertEquals(1, vehicles.size());
    Assert.assertEquals("Dodge", vehicles.get(0).getBrand());
}

Conclusion