0
0
JUnittesting~10 mins

Arrange-Act-Assert pattern in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the test method with the correct annotation.

JUnit
@[1]
public void testAddition() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AIgnore
BBefore
CAfter
DTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Before or @After instead of @Test
Forgetting the '@' symbol
2fill in blank
medium

Complete the code to create an instance of Calculator in the Arrange step.

JUnit
public void testAddition() {
    Calculator calculator = new [1]();
    int result = calculator.add(2, 3);
    // assertions
}
Drag options to blanks, or click blank then click option'
ACalculator
BAdd
CTest
DSum
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names instead of class names
Using lowercase instead of class name capitalization
3fill in blank
hard

Fix the error in the assertion statement to check the expected result.

JUnit
assertEquals([1], result);
Drag options to blanks, or click blank then click option'
A"5"
Bresult
C5
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using the actual result as expected value
Using a string instead of an integer
4fill in blank
hard

Fill both blanks to complete the Arrange and Act steps correctly.

JUnit
Calculator calculator = new [1]();
int result = calculator.[2](4, 6);
Drag options to blanks, or click blank then click option'
ACalculator
Badd
Csubtract
DCalculatorTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class name for object creation
Calling a method that does not exist or is incorrect
5fill in blank
hard

Fill all three blanks to complete the Arrange, Act, and Assert steps in the test method.

JUnit
@Test
public void testMultiply() {
    Calculator calculator = new [1]();
    int result = calculator.[2](3, 7);
    assertEquals([3], result);
}
Drag options to blanks, or click blank then click option'
ACalculator
Bmultiply
C21
DCalculatorTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class name
Calling wrong method
Asserting wrong expected value