Bird
0
0

Which annotation is used to write a test class in Spring Boot?

easy📝 Syntax Q12 of 15
Spring Boot - Testing Spring Boot Applications
Which annotation is used to write a test class in Spring Boot?
A@SpringBootTest
B@Controller
C@Service
D@Repository
Step-by-Step Solution
Solution:
  1. Step 1: Identify the test class annotation in Spring Boot

    @SpringBootTest is used to load the full application context for testing.
  2. Step 2: Check other annotations

    @Controller, @Service, and @Repository are for app components, not tests.
  3. Final Answer:

    @SpringBootTest -> Option A
  4. Quick Check:

    Test class annotation = @SpringBootTest [OK]
Quick Trick: Use @SpringBootTest to run Spring Boot tests [OK]
Common Mistakes:
  • Using @Controller or @Service for tests
  • Confusing component annotations with test annotations
  • Forgetting to annotate test classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes