Creating unit tests

For unit testing, we are using a JUnit, which is a popular Java-based unit testing library. The following source code shows the 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. The @RunWith(SpringRunner.class) annotation provides Spring's ApplicationContext and gets beans injected into your test instance:

@RunWith(SpringRunner.class)@SpringBootTestpublic class MyTestsClass {  @Test  public void testMethod() {    ...  }}

First, we will create our first test case, which will test the major functionality of our application ...

Get Hands-On Full Stack Development with Spring Boot 2 and React - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.