Testing REST API

In Pom.xml add below:

Complete Pom.xml as below given:

Add testing code as below. Test/java/com/javabykiran/springboot folder

Run this code as junit test.

Note that we have added some annotations here to run the tests in a web environment.

@RunWith(SpringJUnit4ClassRunner.class) supports loading of the Spring application context.

@ContextConfiguration defines class-level metadata that is used to determine how to load and configure a context for integration tests. [main class used for developing rest api]

@TestPropertySource is used to configure the values of properties files.

SpringBootTest tells Spring Boot to go and look for a main configuration class (one with @SpringBootApplication, for instance) and use that to start a Spring application context.