0
0
Spring Bootframework~20 mins

@SpringBootTest for integration tests - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SpringBootTest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does @SpringBootTest do in a test class?

Consider a test class annotated with @SpringBootTest. What is the main effect of this annotation when running the test?

AIt loads the full Spring application context for integration testing.
BIt only loads the web layer components without starting the full context.
CIt mocks all Spring beans automatically to isolate the test.
DIt disables Spring context loading and runs tests as plain unit tests.
Attempts:
2 left
💡 Hint

Think about whether the whole app context is started or just parts of it.

📝 Syntax
intermediate
2:00remaining
Which @SpringBootTest property controls the web environment?

Look at these options for @SpringBootTest(webEnvironment = ...). Which one starts the embedded server on a random port?

AWebEnvironment.DEFINED_PORT
BWebEnvironment.MOCK
CWebEnvironment.NONE
DWebEnvironment.RANDOM_PORT
Attempts:
2 left
💡 Hint

Random port means the server starts on any free port to avoid conflicts.

🔧 Debug
advanced
2:00remaining
Why does this @SpringBootTest fail to inject a bean?

Given this test class:

  @SpringBootTest
  public class MyServiceTest {
    @Autowired
    private MyService myService;

    @Test
    void testService() {
      assertNotNull(myService);
    }
  }

The test fails because myService is null. What is the likely cause?

AThe <code>@SpringBootTest</code> annotation is missing the <code>classes</code> attribute specifying the config.
BThe <code>MyService</code> bean is not annotated with <code>@Service</code> or <code>@Component</code>.
CThe <code>myService</code> field should be static for injection to work.
DThe test class is missing <code>@RunWith(SpringRunner.class)</code> annotation.
Attempts:
2 left
💡 Hint

Check if the bean is properly registered in the Spring context.

state_output
advanced
2:00remaining
What is the output of this @SpringBootTest with properties override?

Consider this test class:

@SpringBootTest(properties = {"app.feature.enabled=false"})
public class FeatureTest {

  @Value("${app.feature.enabled}")
  private boolean featureEnabled;

  @Test
  void testFeatureFlag() {
    System.out.println(featureEnabled);
  }
}

What will be printed when the test runs?

Afalse
Btrue
Cnull
DThrows an exception due to missing property
Attempts:
2 left
💡 Hint

Properties in @SpringBootTest override application properties.

🧠 Conceptual
expert
3:00remaining
Why prefer @SpringBootTest over @WebMvcTest for full integration tests?

Which reason best explains why @SpringBootTest is preferred over @WebMvcTest for full integration testing?

A@WebMvcTest disables Spring Security, so it cannot test secured endpoints.
B@SpringBootTest runs tests faster because it loads fewer beans than @WebMvcTest.
C@SpringBootTest loads the entire application context including services and repositories, enabling end-to-end testing.
D@WebMvcTest automatically mocks all dependencies, so it cannot test real database interactions.
Attempts:
2 left
💡 Hint

Think about how much of the app is loaded and tested.