Complete the code to set the test instance lifecycle to per class.
@TestInstance([1]) public class CalculatorTest { // test methods }
The @TestInstance annotation with PER_CLASS sets the lifecycle so that one test instance is used for all tests in the class.
Complete the code to import the correct TestInstance annotation.
import org.junit.jupiter.api.[1]; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CalculatorTest { // test methods }
Test instead of TestInstance.The TestInstance annotation is imported from org.junit.jupiter.api to control test instance lifecycle.
Fix the error in the lifecycle annotation usage.
@TestInstance(TestInstance.Lifecycle.[1]) public class CalculatorTest { // test methods }
The correct lifecycle value to use for one instance per class is PER_CLASS. Other options like PER_INSTANCE or PER_TEST are invalid.
Fill both blanks to complete the test class with lifecycle per class and a test method.
@TestInstance([1]) public class CalculatorTest { @Test public void testAdd() { int result = 2 + 3; assertEquals([2], result); } }
The test instance lifecycle is set to PER_CLASS and the assertion checks that 2 + 3 equals 5.
Fill all three blanks to complete the test class with lifecycle per class, a test method, and an import.
import org.junit.jupiter.api.[1]; import static org.junit.jupiter.api.Assertions.[2]; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class CalculatorTest { @Test public void testMultiply() { int result = 3 * 4; [3](12, result); } }
The import for TestInstance is needed, the assertion method assertEquals is imported and used to check that 3 * 4 equals 12.