Fully embedded Spring Boot app tests
We did some nice testing of the web controller and verified that it behaves properly. But that was just another slice. At some point, it's good to test the whole thing, end-to-end. And with today's modern suite of test tools, it's totally doable.
Spring Boot doesn't always support every tool. For example, Selenium WebDriver, a popular browser automation toolkit, is not yet supported outside of servlets.
No problem! What we really need is for Spring Boot to launch our application, preferably on an unoccupied port, and get out of the way while we do some testing. So let's do just that.
We can start by crafting a new test case like this:
@RunWith(SpringRunner.class) @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class EndToEndTests {
This preceding test class can be described as follows:
@RunWith(SpringRunner.class)
ensures the Spring Boot annotations integrate with JUnit.@SpringBootTest
is the test...