Integration Tests in Spring Boot with MockMvc, DBUnit and H2 | Spring Boot Backend #9.2
In this video I show how to write integration tests in Spring Boot with MockMvc against controllers. Then, I show how to write tests in Spring Boot with DBUnit and H2 against a database.
This is the second part of the ninth video of a playlist where I show how to create a Spring Boot Backend, how to create a website: • Spring Boot
Here is the content of the video:
* Write integration tests in Spring Boot with MockMvc;
* Creation of the Spring context with the @SpringBootTest annotation;
* Injection of the controller where I will test with @Autowired. This controller will be injected in MockMvc;
* Usage of the @MockBean and @SpyBean annotations to inject mocks and spies;
* Make HTTP requests to the controller to test with MockMvc;
* Verification of the obtained results with jsonPath;
* Creation of a in-memory database with H2;
* Injection of the data in the in-memory database H2 with the annotation @DatabaseSetup;
* Usage of the Listeners to handle the transactions, the Spring context and the cleansed of the database.
Repository: github.com/ser...
My NEW eBook: sergiolema.dev...
Blog: bit.ly/47ornJL
LinkedIn: bit.ly/41Nn61q
Facebook: bit.ly/47rc9nh
Boost your APIs with API Monitor: bit.ly/4d7C0ny
Sound from Zapsplat.com
Пікірлер: 9
I love seri your video and I hope you will make more video about Spring Boot Cloud gateway
@TheDevWorldbySergioLema
2 жыл бұрын
Thank you
10:06 Why does he add the dependency and what exactly does it do?
@TheDevWorldbySergioLema
Жыл бұрын
This dependency, H2 (www.h2database.com/html/main.html), is an embedded database. I use H2 to mount a database and destroy it when I finish running the tests. This way, I don't need a side PostgreSQL or MySQL.
@jona312312
Жыл бұрын
@@TheDevWorldbySergioLema Okay, i think i am beginning to understand. Thanks a lot for the reply :D
Does it possible to use DBunit with R2DC connection?
@TheDevWorldbySergioLema
Жыл бұрын
Never tried, but I think yes. Take a look here, github.com/r2dbc/r2dbc-h2