0
0
JUnittesting~5 mins

Spring Boot @SpringBootTest in JUnit - Cheat Sheet & Quick Revision

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

@SpringBootTest tells Spring Boot to start the full application context for integration testing. It helps test how components work together in a real environment.

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 is started during tests. Options include MOCK (no real server), RANDOM_PORT, DEFINED_PORT, and NONE.

Click to reveal answer
beginner
Why should you avoid using @SpringBootTest for simple unit tests?

Because it loads the full application context, which is slow and resource-heavy. For simple unit tests, use lighter annotations or plain JUnit tests.

Click to reveal answer
intermediate
How can you use @SpringBootTest to run tests with a specific profile?
<p>You can add <code>@ActiveProfiles("test")</code> on the test class to activate the <code>test</code> profile during the test run.</p>
Click to reveal answer
What does @SpringBootTest do when placed on a test class?
ALoads the full Spring application context for integration testing
BMocks all dependencies automatically
CRuns only unit tests without Spring context
DStarts only the web layer for testing
Which webEnvironment option starts a real server on a random port during @SpringBootTest?
AMOCK
BDEFINED_PORT
CNONE
DRANDOM_PORT
Which annotation activates a specific Spring profile during a @SpringBootTest?
A@ActiveProfiles
B@TestProfile
C@Profile
D@SpringProfile
Why might @SpringBootTest tests run slower than unit tests?
ABecause they run in a separate JVM
BBecause they use more CPU-intensive assertions
CBecause they load the full Spring application context
DBecause they skip dependency injection
Which annotation is best for testing only Spring MVC controllers without loading the full context?
A@SpringBootTest
B@WebMvcTest
C@DataJpaTest
D@RestControllerTest
Explain what @SpringBootTest does and when you should use it.
Think about testing the whole app versus parts.
You got /4 concepts.
    Describe how to configure @SpringBootTest to run tests with a specific Spring profile and why this is useful.
    Profiles help customize app behavior for tests.
    You got /4 concepts.