Creating unit tests
For unit testing, we are using JUnit, which is a popular Java-based unit testing library. 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 } }
First, we will create our first test case that will test the major functionality of our application before we create any formal test cases. Proceed as follows:
- Open the
CardatabaseApplicationTest
test class that has already been made for your application. There is one test method calledcontextLoads
here, and this is where we will add the test. The...