Spring Boot Application is starting up from a JUnit test but unable to access through URL

前端 未结 1 1675
感情败类
感情败类 2021-01-27 08:46

I have a JUnit Test that starts my spring boot appcliation (Application.java).

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public c         


        
相关标签:
1条回答
  • 2021-01-27 09:05

    Why would you do such thing? This should be a unit test and the flow of the test should be the following: Start the application -> Call your controller endpoint -> assert that a specific text/element on that page is present -> Shut down the application.

    Start the application : @RunWith(SpringRunner.class) doing this for you, no need to start is manually.

    Shut down the application : At the end of your test class Spring boot does this for you (That's why you cant access your app in the browser)

    For further help please see my answer here: How to test (rest) enpoints

    0 讨论(0)
提交回复
热议问题