Architecture of a REST back-end - Separating RestControllers and Data

by ScriptKiddy   Last Updated March 26, 2018 07:05 AM

So i have recently started looking into REST. My language of choice is Kotlin and i am using the Spring framework. One of my goals was and still is to achieve 100% test coverage, since i will only create the back-end and won't know anything about the front-end.

All my controllers, which are the classes that are annotated with RestController are automatically initialized by Spring. In order to use one controller from within another, i am using Springs Autowire annotation, which automatically references the controller that was earlier initialized, meaning you will always use the same controller everywhere.

During runtime, all of that is fine. It is totally fine that my controllers are actually not stateless. But, if i know want to unit test the endpoints, i am running into problems due to state, i have to cleanup all data after each test that ran, which is obviously quite annoying and error prone.

So i have been asking myself what i could to, furthermore how i'd be able to extract the data from within the controllers and achieve testability and simplicity. Another goal is to not pollute my code in order to make it testable.

Related Questions

How to I best test this method? Do I need to split it up?

Updated September 15, 2016 09:02 AM

Implementing a REST API in a Clean Architecture

Updated July 01, 2018 09:05 AM

Using Spring in Java Project

Updated February 29, 2016 01:02 AM

Testing front-end app that hits a REST service

Updated April 08, 2015 19:02 PM