spring-boot-starter-test
.spring-boot-starter-test
includes the essential dependencies for test, such as json-path, assertj, hamcrest, mockito etc.@SpringBootTest
to unite the old @IntegrationTest
, @WebIntegrationTest
, @SpringApplicationConfiguration
etc, in before versions.webEnvironment
property of @SpringBootTest
is use for deciding if set up a web environment for test.webEnvironment
.@LocalSeverPort
annotation on an int
field will inject the port number at runtime.@LocalServerPort
replaces the @Value("${local.server.port}")
of Spring Boot 1.3.@SpringApplicationConfiguration
. You can specify the configuration classes to be loaded for the test.@SpringApplicationConfiguration(classes={...})
in Spring Boot 1.3.SpringRunner
, which is an alias for the SpringJUnit4ClassRunner
.SpringRunner
, and want to use the Spring test context in the tests, declare a SpringClassRule
and SpringMethodRule
in the test to fill the gap.MockMvc
in the test.SpringBootTest
, they are combined with a series of AutoconfigureXXX
and a @TypeExcludesFilter
annotations.@DataJpaTest
.@AutoconfigureXXX
annotation to override the default config.@JsonComponent
is a specific @Component
to register custome Jackson JsonSerializer
and JsonDeserializer
.JsonSerializer
and JsonDeserializer
are use for serializing and deserializing LocalDateTime
instance.ObjectMapper
bean in your configuration, the auto configuration of ObjectMapper
is disabled. You have to install JsonComponentModule
manually, else the @JsonComponent
beans will not be scanned at all.@MockBean
and @MockSpy
annotations.TestConfiguration
and TestComponent
are designated for test purpose, they are similar with Configuration
and Component
. Generic Configuration
and Component
can not be scanned by default in test codes.@RestControllerAdvice()
is provided for exception handling, it is combination of @ControllerAdvice
and @ResponseBody
. You can remove the @ResponseBody
on the @ExceptionHandler
method when use this new annotation.@Inject
or @Autowired
on the constructor to inject the dependencies.@Inject
can be removed in Spring 4.3.passwordEncoder
and userDetailsService
via AuthenticationManagerBuilder
.userDetailsService
and passwordEncoder
bean can be detected automatically. No need to wire them by AuthenticationManagerBuilder
manually. No need to override the WebSecurityConfigurerAdapter
class and provide a custom configuration, a generic WebSecurityConfigurerAdapter
bean is enough.spring-orm
, spring-boot-data-jpa-starter
which depends on hibernate-entitymanager. Spring Boot 1.4.0.RC1 and Spring 4.3 GA fixed the issues. But I noticed in the Hibernate 5.2.1.Final, hibernate-entitymanager is back.