0

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?

Mars
  • 21
  • 5

1 Answers1

2

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).

Mars
  • 21
  • 5
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '22 at 11:26