Creating test cases
For unit and integration testing, we are using JUnit, which is a popular Java-based unit testing library. Spring Boot has built-in support for JUnit, making it easy to write tests for your Spring Boot application. The following source code shows an example skeleton of the Spring Boot test class. The @SpringBootTest
annotation specifies that the class is a regular test class that runs Spring Boot-based tests. The @Test
annotation before the method specifies to JUnit that the method can be run as a test case:
@SpringBootTest
public class MyTestsClass {
@Test
public void testMethod() {
// Test case code
}
}
Assertions in unit testing are statements that can be used to verify whether the actual output of a code unit matches the expected output. In our case, the assertions are implemented using the AssertJ library that the spring-boot-starter-test artifact automatically includes. The AssertJ library provides assertThat()
method that you can use to write assertions...