testing-pyramid

Solid

Use when writing tests of any kind — unit, slice, or integration. Covers test structure, naming conventions, Mockito patterns, @WebMvcTest, @DataJpaTest, and Testcontainers setup.

Testing & QA 225 stars 37 forks Updated 6 days ago MIT

Install

View on GitHub

Quality Score: 88/100

Stars 20%
78
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Testing Pyramid ## Structure ``` Unit Tests — fast, no Spring context, mock dependencies (70%) Slice Tests — partial Spring context (@WebMvcTest, @DataJpaTest) (20%) Integration Tests — full context + real DB via Testcontainers (10%) ``` ## Unit Tests — Services ```java @ExtendWith(MockitoExtension.class) class OrderServiceTest { @Mock private OrderRepository orderRepository; @Mock private InventoryService inventoryService; @InjectMocks private OrderService orderService; @Test void createOrder_whenItemsAvailable_shouldSaveAndReturnOrder() { // Given var request = new CreateOrderRequest("user@example.com", List.of(new OrderItemRequest(UUID.randomUUID(), 2))); var savedOrder = Order.create("user@example.com"); when(orderRepository.save(any(Order.class))).thenReturn(savedOrder); doNothing().when(inventoryService).reserve(any()); // When Order result = orderService.createOrder(request); // Then assertThat(result).isNotNull(); assertThat(result.getCustomerEmail()).isEqualTo("user@example.com"); verify(inventoryService).reserve(request.items()); verify(orderRepository).save(any(Order.class)); } @Test void createOrder_whenInventoryUnavailable_shouldThrowException() { // Given var request = new CreateOrderRequest("user@example.com", List.of()); doThrow(new InsufficientInventoryException("Out of stock...

Details

Author
rrezartprebreza
Repository
rrezartprebreza/spring-boot-skills
Created
4 months ago
Last Updated
6 days ago
Language
Java
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category