Skip to content
AgileLogics
4 min read

Testing Strategies

Prerequisites: Building a REST API with Spring Boot

A unit test (from Level 2) verifies one class in isolation; an integration test verifies several real pieces working together (e.g. a controller, a service, and a real test database).

class OrderServiceTest {
    @Test
    void appliesDiscountForLargeOrders() {
        var paymentGateway = mock(PaymentGateway.class); // a test double
        var service = new OrderService(paymentGateway);

        double total = service.calculateTotal(150.0);

        assertEquals(135.0, total); // 10% off orders over 100
    }
}

A mock, as used above (via a library like Mockito), stands in for a real dependency (here, a payment gateway) so the test can verify OrderService's logic without actually contacting a real payment provider.