Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to specify the execution order of the test method using @Order.
JUnit
@Test
@Order([1])
void testFirst() {
// test logic here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or negative numbers.
Omitting the @Order annotation and expecting order.
✗ Incorrect
The @Order annotation takes an integer value to specify the order. Lower numbers run first. Use '1' for the first test method.
2fill in blank
mediumComplete the code to import the correct package for the @Order annotation.
JUnit
import [1]; @Test @Order(2) void testSecond() { // test logic }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing @Order from the wrong package causing compilation errors.
Confusing @Order with @Test import.
✗ Incorrect
The @Order annotation is part of the JUnit Jupiter API package 'org.junit.jupiter.api.Order'.
3fill in blank
hardFix the error in the test class to ensure methods run in the specified order.
JUnit
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; @TestMethodOrder([1].class) class MyTests { @Test @Order(1) void firstTest() {} @Test @Order(2) void secondTest() {} }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Order instead of OrderAnnotation in @TestMethodOrder.
Using MethodOrderer.class which is an interface, not a class.
✗ Incorrect
The @TestMethodOrder annotation requires a class that implements MethodOrderer. 'OrderAnnotation.class' is the correct class to specify ordering by @Order.
4fill in blank
hardFill both blanks to create a test class that runs testOne first (@Order(1)), then testThree (@Order(3)).
JUnit
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; @TestMethodOrder([1].class) class OrderedTests { @Test @Order([2]) void testOne() {} @Test @Order(3) void testThree() {} }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class in @TestMethodOrder.
Setting @Order values incorrectly causing wrong execution order.
✗ Incorrect
Use @TestMethodOrder(OrderAnnotation.class) to enable ordering by @Order. The testOne method should have @Order(1) to run before testThree with @Order(3).
5fill in blank
hardFill all three blanks to define a test class with three tests running testFirst (@Order(1)) first, testSecond (@Order(2)), then testThird (@Order(3)).
JUnit
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; @TestMethodOrder([1].class) class MultiOrderTests { @Test @Order([2]) void testSecond() {} @Test @Order([3]) void testThird() {} @Test @Order(1) void testFirst() {} }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up order numbers causing unexpected test execution order.
Forgetting to use OrderAnnotation.class in @TestMethodOrder.
✗ Incorrect
Use @TestMethodOrder(OrderAnnotation.class) to enable ordering. Set @Order(2) for testSecond and @Order(3) for testThird so the execution order is testFirst(1), testSecond(2), testThird(3).