Overview

Testing prevents regressions and speeds up development. Spring Boot’s built-in testing tools allow fast, reliable, and isolated checks without the inefficiency of manual methods like Postman.

Why

  • Manual testing comes with several inconveniences:
    • You have to start the server and open Postman every time, which is tedious.
    • As the number of test cases grows, the repeated work becomes overwhelming.
    • It’s difficult to test specific functions (e.g., a single method) in isolation.
CategoryManual TestingAutomated Testing (e.g., Unit Tests)
Execution MethodDeveloper manually uses Postman, etc.Click a button in the IDE or run automatically via CI
RepeatabilityInefficient, time-consumingCan be repeated quickly
Scope of VerificationBroad (focused on checking overall flow)Precise verification down to individual functions
ProductivityLow (burdensome when repeated)High (done with a single click)
Refactoring SafetyLowHigh

Types of testing in Spring

Diagram

Types of tests

Test TypeMain PurposeTest ScopeCharacteristicsTool/AnnotationCode examples
Unit Test (단위 테스트)Verify functionality of small units (methods, classes)Very narrowNo Spring Context loaded. Extremely fast, completely isolated from other parts of the application.- JUnit 5
- Mockito
- AssertJ
- Example - service unit testing
Slice TestTest specific layers in layered architecture (e.g., Controller, Repository) in isolationMediumLoads a partial Spring Context.
Fast, but slower than a unit test.
Uses mocks for dependencies outside the slice.
- @WebMvcTest (Controller)
- [[Data Access (Repository) Layer Testing#@DataJpaTest|@DataJpaTest]]
- Mockito
- Example - controller test
Integration Test (통합 테스트)Verify interactions between multiple layers including database and servicesBroadLoads the full Spring Context. Slower, as it involves real components, network calls, and database connections.@SpringBootTest TestRestTemplate
@Transactional (for DB tests)
Functional Test (기능 테스트)Verify the application behaves correctly from the user/client perspective, testing multiple components
- client vs server
Very BroadSimulates real-world usage. Tests a complete feature workflow, often involving the entire running application.External tools (Selenium, Postman), or full-stack @SpringBootTest