Annotation notes when writing tests for Spring Boot

Overview

A brief note and reference link for each annotation used in the Spring Boot test Use JUnit 5

Library used during the trial

build.gradle


testImplementation('org.springframework.boot:spring-boot-starter-test:2.1.5.RELEASE'){
		exclude module: 'junit'
	}
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2'

References

@SpringBootTest Declare when testing or mocking the component registered as a bean in the DI container

--Create a DI container (ʻApplicationContext) --You can't @Autowiredthe class you want to test without this --If you set thewebEnvironment` attribute, the server will be started when the test is executed. --By default, it provides a Mock Web environment without starting a server.

46.3 Testing Spring Boot Applications

@WebMvcTest Declare when testing @ Controller or @ RestController

--Create a DI container (ʻApplicationContext) only for the @Controllercomponent --AllowsMockMvc to be @ Autowired`

46.3.10 Auto-configured Spring MVC Tests

@RestClientTest Declare when testing a component that communicates with Http

--Allows MockRestServiceServer to be @ Autowired

46.3.20 Auto-configured REST Clients

Recommended Posts

Annotation notes when writing tests for Spring Boot
Spring Boot for annotation learning
Frequent annotations for Spring Boot tests
Spring boot memo writing (1)
Spring boot memo writing (2)
Use Spring Test + Mockito + JUnit 4 for Spring Boot + Spring Retry unit tests
Various switching application.properties for each environment when Spring Boot starts
Spring Boot for the first time
Use DBUnit for Spring Boot test
Thymeleaf usage notes in Spring Boot
[Ruby] Writing notes for cherry books [Notes for yourself]
Story when moving from Spring Boot 1.5 to 2.1
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
WebMvcConfigurer Memorandum of Understanding for Spring Boot 2.0 (Spring 5)
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
How to not start Flyway when running unit tests in Spring Boot
Javaw.exe error when starting Spring Boot (STS)
Book introduction: Spring Boot Recommended reference book for beginners!
Write RestController tests quickly with Spring Boot + Spock
When @Transactional of Spring Boot does not work
Spring --Error / Error avoidance when creating API for POST
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
Plans to support JDK 11 for Eclipse and Spring Boot
[Note] Configuration file when using Logback with Spring Boot
How to set Dependency Injection (DI) for Spring Boot
Switch environment with Spring Boot application.properties and @Profile annotation
How to write a unit test for Spring Boot 2
[Spring Boot] How to create a project (for beginners)
Customizer for Platform Transaction Manager added from Spring Boot 1.5
A memorandum when creating a REST service with Spring Boot