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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.