Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

stealthrabbi/spring-boot-mvc-test

Repository files navigation

spring-boot-mvc-test

A Test Spring Boot application that uses Spring MVC Controllers and is unit tested.

There's also an example of populating a spring bean with values from a properties file (AppPropertiesContainer).

unit test result badge

Build and Test

Dependencies

All dependencies are managed in the build.gradle file.

Explanation of Code

This is a Spring Boot application. AppBootMain contains the main function that builds the application as a Spring Boot web app.

The domain_model package has a simple POJO class that gets returned by the Controller.

The data_repository package has a simple Repository class and interface representing a data store. The concreate class just contains a static list of objects. The interface exists so the dependency can be mocked using Mockito.

The web_controllers package contains Spring MVC Controllers that map REST URIs to methods that return objects.

View the test package to see Spring Tests for the Controllers. AbstractSpringTest is a simple base class to be used for all unit tests for spring managed classes. AbstractControllerTest sets up a MockMvc to invoke calls on the REST interface. StudentControllerTest tests the StudentController Controller. It creates a mockito mock for the StudentRepository and injects it in to the controller. MockMvc is used to invoke calls on the REST interface and check returned JSON values.

About

A Test Spring Boot application that uses Spring MVC Controllers and unit tested.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.