Spring Boot Unit Testing REST APIs Tutorial

preview_player
Показать описание
In this video tutorial, you will learn how to code unit tests for REST APIs with Spring framework, Spring Boot, Spring MVC, Spring Test, JUnit, Mockito with full code examples. In other words, how to test REST controllers with Spring Boot and related technologies.

In details, I'll show you:
- What is Unit Testing for REST APIs
- How to Code Unit Testing for REST APIs with Spring Boot
- Code Unit Tests for Sample User REST APIs (Test Add, Get, List, Update & Delete Operations)

Timestamps
0:00 - Introduction
1:20 - What is Unit Testing REST APIs
2:39 - How Unit Testing REST APIs with Spring Boot
5:39 - Demo Existing Spring Boot Project
10:25 - Sample User REST APIs
11:16 - Create Test Class
14:09 - Code Unit Test for Add User API Expect Status 400
21:54 - Code Unit Test for Add User API Expect Status 201
36:30 - Code Unit Test for Get User API Expect Status 404
41:54 - Code Unit Test for Get User API Expect Status 200
46:32 - Code Unit Test for List Users API Expect Status 204
52:04 - Code Unit Test for List Users API Expect Status 200
57:39 - Code Unit Test for Update User API Expect Status 404
1:04:37 - Code Unit Test for Update User API Expect Status 400
1:06:46 - Code Unit Test for Update User API Expect Status 200
1:09:46 - Code Unit Test for Delete User API Expect Status 404
1:14:08 - Code Unit Test for Delete User API Expect Status 204

Рекомендации по теме
Комментарии
Автор

This video is very detailed of testing in controller. Hope you make another one for testing with mockito in service class.

ktn
Автор

Thank you very much because the values you bring to people

minhoan
Автор

This is an interesting and useful video. Thanks, brother!!

jasper
Автор

Citrus framework is used also for the same purpose, what do you think of it ?

np
Автор

Why we don't test service repo etc?

anutaNYC
Автор

Hello, I'm facing a problem with the service declared in the test class. I declare the service as yours with @MockBean, but when debugging the service, I notice that the repository in the service is null, which prevents me from doing succesfully the second test. When debugging the application by running it normally, the repository is not null, so I assume the problem comes from the declaration in the test class. I'm a beginner so I don't fully understand how spring boot works, so do you have any idea ?

ziberty
Автор

Good example and good experience.
Is this code uploaded in git repository
Thanks

MBalekundri
Автор

I thought that ResponseEntity<?> is a bad habit because java is typed language

Metanabolix
Автор

Do you have any courses that cover everything?

amiisomer
Автор

Can you give me library or dependency which help you can create an variable with line "User newUser = new ( 16'56s in this video)? Thanks :v

DaoNguyenHuu-ifsi