5. You have a JUnit test class with methods annotated with @Order values 1, 2, and 2. What will happen when you run the tests with @TestMethodOrder(OrderAnnotation.class)?
hard
A. Tests with duplicate order values are skipped.
B. JUnit throws a runtime error due to duplicate order values.
C. Tests with the same order value run in declaration order among themselves.
D. Tests run in random order ignoring the duplicate values.
Solution
Step 1: Understand behavior with duplicate @Order values
JUnit allows duplicate order values; tests with the same order run in the order they appear in the code.
Step 2: Check other options
JUnit does not throw errors or skip tests due to duplicate order values, nor does it randomize them.
Final Answer:
Tests with the same order value run in declaration order among themselves. -> Option C
Quick Check:
Duplicate @Order runs in code order [OK]
Hint: Duplicate @Order runs in source code order [OK]
Common Mistakes:
Expecting errors on duplicate @Order values
Assuming tests with same order run randomly
Thinking duplicates cause tests to skip
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.