Complete the code to create a simple Spring Boot test class.
import org.springframework.boot.test.context.[1]; @[1] public class ApplicationTests { }
The @SpringBootTest annotation tells Spring Boot to look for a main configuration class and start the application context for testing.
Complete the code to write a test method that checks if the application context loads.
@Test
public void context[1]() {
// test body can be empty
}The method name contextLoads is a common convention in Spring Boot tests to verify the application context starts without errors.
Fix the error in the test annotation import statement.
import org.junit.jupiter.api.[1]; @[1] public void testExample() { // test code }
The correct import for JUnit 5 test methods is org.junit.jupiter.api.Test. This annotation marks a method as a test.
Fill both blanks to create a test that asserts two values are equal.
@Test
public void testSum() {
int result = 2 + 3;
[1].assert[2](5, result);
}Use Assertions.assertEquals(expected, actual) to check if two values are equal in JUnit 5.
Fill all three blanks to write a test that verifies a service method returns the expected string.
import static org.junit.jupiter.api.Assertions.[1]; @Test public void testGreeting() { MyService service = new MyService(); String greeting = service.[2](); [3]("Hello, World!", greeting); }
The test imports assertEquals to compare expected and actual values. It calls getGreeting() on the service and asserts the result equals "Hello, World!".