0
0
Spring Bootframework~5 mins

@SpringBootTest for integration tests - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @SpringBootTest annotation in Spring Boot?

@SpringBootTest tells Spring Boot to start the full application context for integration testing. It helps test how different parts of the app work together.

Click to reveal answer
intermediate
How does @SpringBootTest differ from unit testing annotations like @WebMvcTest?

@SpringBootTest loads the entire application context, while @WebMvcTest loads only web layer components for focused controller tests.

Click to reveal answer
intermediate
What does the webEnvironment attribute in @SpringBootTest control?

It controls how the embedded web server starts during tests. Options include MOCK (no real server), RANDOM_PORT, DEFINED_PORT, or NONE.

Click to reveal answer
beginner
Why is @SpringBootTest considered slower than unit tests?

Because it loads the full Spring application context, which takes more time than loading only small parts for unit tests.

Click to reveal answer
intermediate
How can you use @SpringBootTest to run tests with a random port?

Use @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) to start the server on a random port for real HTTP testing.

Click to reveal answer
What does @SpringBootTest do in a test class?
ALoads the full Spring application context for integration testing
BMocks only the web layer components
CRuns unit tests without Spring context
DStarts a database server
Which webEnvironment option starts a real server on a random port?
AMOCK
BRANDOM_PORT
CNONE
DDEFINED_PORT
Why might @SpringBootTest tests run slower than unit tests?
ABecause they load the full application context
BBecause they use more CPU
CBecause they skip database setup
DBecause they don't use Spring
Which annotation is better for testing only Spring MVC controllers?
A@DataJpaTest
B@SpringBootTest
C@WebMvcTest
D@MockBean
Can @SpringBootTest be used to test database integration?
AOnly if combined with @DataJpaTest
BNo, it only tests web controllers
CNo, it mocks database calls
DYes, because it loads full context including database beans
Explain what @SpringBootTest does and when you would use it.
Think about testing the whole app, not just one part.
You got /4 concepts.
    Describe the difference between @SpringBootTest and @WebMvcTest.
    One tests everything, the other tests only controllers.
    You got /4 concepts.