Complete the code to import the JUnit Test annotation.
import org.junit.[1]; public class SampleTest { @Test public void testExample() { // test code } }
The @Test annotation marks a method as a test method in JUnit.
Complete the code to assert that two values are equal.
import static org.junit.Assert.[1]; public class SampleTest { @Test public void testSum() { int result = 2 + 3; assertEquals(5, result); } }
assertEquals checks if two values are equal in JUnit tests.
Fix the error in the test method to notify failure correctly.
import static org.junit.Assert.assertEquals; public class SampleTest { @Test public void testFailNotification() { int expected = 10; int actual = 5; assertEquals([1], actual); } }
The first argument to assertEquals is the expected value, then the actual value.
Fill both blanks to create a test that fails with a custom message.
import static org.junit.Assert.assertEquals; public class SampleTest { @Test public void testFailWithMessage() { assertEquals([1], [2], 100); } }
The first argument is the failure message, the second is the expected value.
Fill all three blanks to write a test that fails if a condition is false with a message.
import static org.junit.Assert.assertTrue; public class SampleTest { @Test public void testCondition() { assertTrue([1], [2] > [3]); } }
The first argument is the failure message, then the condition checks if x is greater than y.
