0
0
Spring Bootframework~10 mins

Why testing matters in Spring Boot - Test Your Understanding

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

Complete the code to create a simple Spring Boot test class.

Spring Boot
import org.springframework.boot.test.context.[1];

@[1]
public class ApplicationTests {

}
Drag options to blanks, or click blank then click option'
ASpringBootTest
BComponent
CService
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @SpringBootTest for test classes
Forgetting to import the correct annotation
2fill in blank
medium

Complete the code to write a test method that checks if the application context loads.

Spring Boot
@Test
public void context[1]() {
    // test body can be empty
}
Drag options to blanks, or click blank then click option'
AStarts
BLoads
CRuns
DChecks
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that don't reflect the test purpose
Leaving out the @Test annotation
3fill in blank
hard

Fix the error in the test annotation import statement.

Spring Boot
import org.junit.jupiter.api.[1];

@[1]
public void testExample() {
    // test code
}
Drag options to blanks, or click blank then click option'
ATestCase
BTestMethod
CTestAnnotation
DTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using JUnit 4 imports with JUnit 5 annotations
Misspelling the annotation name
4fill in blank
hard

Fill both blanks to create a test that asserts two values are equal.

Spring Boot
@Test
public void testSum() {
    int result = 2 + 3;
    [1].assert[2](5, result);
}
Drag options to blanks, or click blank then click option'
AAssertions
BassertEquals
CassertTrue
DAssert
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertTrue instead of assertEquals for equality checks
Using Assert instead of Assertions in JUnit 5
5fill in blank
hard

Fill all three blanks to write a test that verifies a service method returns the expected string.

Spring Boot
import static org.junit.jupiter.api.Assertions.[1];

@Test
public void testGreeting() {
    MyService service = new MyService();
    String greeting = service.[2]();
    [3]("Hello, World!", greeting);
}
Drag options to blanks, or click blank then click option'
AassertEquals
BgetGreeting
CassertTrue
DsayHello
Attempts:
3 left
💡 Hint
Common Mistakes
Using assertTrue instead of assertEquals for string comparison
Calling a non-existent method on the service