Spring Boot 2 JUnitο
By default, Spring boot uses Junit 4. To write tests in Junit 5, read this migration guide : Junit 5 with Spring boot 2.
JUnit Test Classο
@RunWith(SpringRunner.class)
β tells JUnit to run using Springβs testing support. SpringRunner is the new name forSpringJUnit4ClassRunner
. It enables full support of spring context loading and dependency injection of the beans in the tests.@SpringBootTest
β annotation that can be specified on a test class that runs Spring Boot based tests. It provides ability to start a fully running web server listening on any defined or random port.webEnvironment
β enables requests and responses to travel over network and mock servlet container is not involved.@LocalServerPort
β injects the HTTP port that got allocated at runtime.