Bird
0
0

What will happen when this Spring Boot test runs?

medium📝 component behavior Q13 of 15
Spring Boot - Testing Spring Boot Applications
What will happen when this Spring Boot test runs?
@SpringBootTest
public class MyAppTests {
  @Test
  void testSum() {
    int result = 2 + 3;
    assertEquals(5, result);
  }
}
AThe test will pass because the sum is correct.
BThe test will be ignored automatically.
CThe test will cause a syntax error.
DThe test will fail because 2 + 3 is not 5.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the test method

    The method calculates 2 + 3 and stores 5 in result, then checks if result equals 5.
  2. Step 2: Determine test outcome

    Since 2 + 3 is 5, assertEquals(5, result) will pass without errors.
  3. Final Answer:

    The test will pass because the sum is correct. -> Option A
  4. Quick Check:

    2 + 3 = 5 test passes [OK]
Quick Trick: Check if assertion matches calculation result [OK]
Common Mistakes:
  • Thinking 2 + 3 is not 5
  • Assuming syntax errors without checking code
  • Believing tests run automatically without @Test

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes