Strong answer
A healthy Java test suite has many fast unit tests for domain rules, focused slice tests for framework boundaries, and a smaller number of integration tests that prove the wiring works. JUnit 5 provides the lifecycle, assertions, and parameterized tests; Mockito replaces collaborators you do not own or that are slow, but mocks should verify behavior at a boundary rather than restate the implementation. Spring slices such as @WebMvcTest and @DataJpaTest load only the relevant part of the context.
Java example
1@WebMvcTest(OrderController.class)
2class OrderControllerTest {
3
4 @Autowired MockMvc mvc;
5 @MockitoBean OrderService service;
6
7 @Test
8 void rejectsInvalidQuantity() throws Exception {
9 mvc.perform(post("/orders")
10 .contentType(MediaType.APPLICATION_JSON)
11 .content("{\"sku\":\"A-1\",\"quantity\":0}"))
12 .andExpect(status().isBadRequest())
13 .andExpect(jsonPath("$.errors[0].field").value("quantity"));
14
15 verifyNoInteractions(service);
16 }
17}
18
19@ParameterizedTest
20@CsvSource({"100, 0", "1000, 50", "5000, 500"})
21void appliesDiscountTiers(int subtotal, int expectedDiscount) {
22 assertEquals(expectedDiscount, pricing.discountFor(subtotal));
23}