Link to get code examples and download sample project: www.codejava.net/frameworks/spring-boot/unit-testing-rest-apis-tutorial
@minhoan7974
8 ай бұрын
Thank you very much because the values you bring to people
@CodeJava
8 ай бұрын
you're welcome. Glad you found this video helpful.
@ktn4
Жыл бұрын
This video is very detailed of testing in controller. Hope you make another one for testing with mockito in service class.
@CodeJava
Жыл бұрын
it was published already here: kzitem.info/news/bejne/yH-YxaFmb4qWhHo
@ziberty3269
Жыл бұрын
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 ?
@CodeJava
Жыл бұрын
It's because WebMvcTest does not load components other than controllers, that's why you see repo in service got null. That's the reason you need to mock your Service class.
@ziberty3269
Жыл бұрын
@@CodeJava Thanks for your answer. However, I already mocked the service class with the @MockBean annotation if I understand correctly ? So I would need to mock the repository in the mocked service, but it worked for you without doing it and I did everything like in your tutorial, assuming you showed everything needed.
@np8688
Жыл бұрын
Citrus framework is used also for the same purpose, what do you think of it ?
@CodeJava
Жыл бұрын
I can't say much because I don't get a chance to use it. It's about integration tests rather than unit tests.
@Metanabolix
Жыл бұрын
I thought that ResponseEntity is a bad habit because java is typed language
@CodeJava
Жыл бұрын
can you suggest alternative to ?
@Metanabolix
Жыл бұрын
@@CodeJava ResponseEntity for example
@amiisomer9758
Жыл бұрын
Do you have any courses that cover everything?
@CodeJava
Жыл бұрын
yes, here it is: www.udemy.com/course/spring-boot-rest-apis-ultimate
@DaoNguyenHuu-if4si
11 ай бұрын
Can you give me library or dependency which help you can create an variable with line "User newUser = new User().email("").firstName("");" ( 16'56s in this video)? Thanks :v
@CodeJava
11 ай бұрын
I wrote that code manually. But you can use Lombok for that. Reference: www.codejava.net/coding/how-to-use-builder-pattern-for-designing-method-parameters
@jasper5016
Жыл бұрын
This is an interesting and useful video. Thanks, brother!!
Пікірлер: 31