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.