Backend Handbook
Leapwise
  • 👋Introduction
  • Software Design Principles & Clean Code
    • Atomicity
    • Modularity
    • Hierarchy
    • Loose coupling
    • Asynchronous programming
  • Development Practices
    • JavaDocs
    • Technical Debt
    • Testing Guidelines
      • The Importance of Test Automation
      • The Testing Pyramid
        • Unit Tests
        • Integration Tests
        • End-to-End Tests
      • Mutation Testing
      • Contract Tests
        • REST Controller Contract testing
        • OpenAPI Contract testing
      • Testing Frameworks
        • JUnit 5
        • Testcontainers
        • Mockito
      • Writing Clean Tests - Best Practices
    • Common library
    • Generic CRUD
    • Update Facade
  • Development Tools & Environment
    • Monitoring
    • Performance tuning
    • Multi-tenancy & Configuration Management
    • Git practices
    • CI/CD
    • Maven
  • Project Management
    • Jira
    • Confluence documentation
    • SCRUM
    • Our ways of working
  • LIFE AT LEAPWISE
    • Introduction
    • Who are we?
    • What do we do?
    • Our values
    • Hiring process
      • Hiring: A Mid Frontend Developer's Point of View
    • Benefits we offer
    • Onboarding process
      • Onboarding: A Senior Digital Marketing Specialist's perspective
    • Mentorship program
    • Career development
      • Trainings & certificates we offer
      • Career development: A Senior Software Developer's Insight
    • Community building
    • Juniorship
    • First-hand info from our first team member
    • Join our team
Powered by GitBook
LogoLogo

Company

  • About
  • Culture
  • Services

Insights

  • Leapwise Newsletter
  • Blog

© Leapwise

On this page
  • Types of Spring Boot Integration Tests
  • 1. Context Loading Test
  • 2. Web Layer Test
  • 3. Repository Test
  • 4. Service Layer Test
  • Conclusion

Was this helpful?

  1. Development Practices
  2. Testing Guidelines
  3. The Testing Pyramid

Integration Tests

PreviousUnit TestsNextEnd-to-End Tests

Last updated 11 months ago

Was this helpful?

Integration testing is the type of testing where we verify the functionality of interactions between different components in our application. These tests help us better understand the internal application processes as they give us an insight into how the application flow actually works.

Integration tests in Spring have somewhat more complicated setup than regular Unit tests. We have to load the Application Context or at least a part of it, so we can autowire Spring beans and test the actual functionalities. This makes Integration tests startup noticeably slower than Unit test.

Types of Spring Boot Integration Tests

Depending on the service and part of the application we want to test, we differ a few Integration test types. It’s important to understand and determine the goal of the test so we can configure the test properly, add the right dependencies.

1. Context Loading Test

  • Ensures that the Spring application context is loaded without any issues.

  • Typically uses @SpringBootTest annotation.

2. Web Layer Test

  • Tests the web layer of the application (controllers, filters, etc.).

  • Uses @WebMvcTest annotation and MockMvc for mocking HTTP requests.

3. Repository Test

  • Tests the persistence layer.

  • Uses @DataJpaTest to configure an in-memory database for testing.

  • Aside from in-memory database, we can configure Test Containers () and spin our DB instances inside Docker containers. This way we can get more realistic (production-like) Integration tests leading to more robust and error proof testing.

4. Service Layer Test

  • Tests the service layer, often involving mocking of dependencies using tools like Mockito.

  • Uses @SpringBootTest and @MockBean to replace the real bean with a mocked one in the application context.

Conclusion

These were just some of the basic examples of integration tests in Spring Boot. To have the complete testing suite of your application, Integration tests are a must for making sure that the application processes work as intended and to avoid production deployment avoidable issues.

Testcontainers
Page cover image