Issue
I am trying to test my SpringBoot Application. When I start it as usual it starts the Tomcat Service as expected and loggs it into the console after the Spring Logo.
When I execute @SpringBootTest Classes however, it appearently doesn't start the Tomcat Service as the URL is not accessible in the Test and after the Spring Logo all Logs regarding the Tomcat Service are Missing.
An answer on Stackoverflow said:
Running a test with @SpringBootTest does start an embedded server by default. By default, it runs in the MOCK environment.
Link: https://stackoverflow.com/a/56077027/16034630
And this is how I understood it. But why do my Tests not start the Application normally with the Tomcat Service included?
Solution
I found a solution by doing this:
Putting the tests all in the hierarchy the Application Class has. My Springboot Main Method is in the class in path src/main/java/"myProject"/"myProjectClassWithMainMethod" and I put all Test Classes in the path src/test/java/"myProject"/test/"TestClasses".
Lastly and most importantly annotation each Testclass with @SpringBootTest and specifying that it should start with defined port by adding (webEnvironment = WebEnvironment.DEFINED_PORT). So every Class has the Annotation @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT).
Answered By - Mars
Answer Checked By - David Goodson (JavaFixing Volunteer)