This isn't a unit test though. This is an implementation test, as you are acutally including API calls. A unit test would simply be testing the method on it's own, without using a restful API. Ideally, one should have both unit and integration tests; after all, the unit test might pass as your method works as expected but your integration test might fail due to the path having changed - or an issue the other way around might arise.
I actually agree with this and I've wrote unit test using just the method. I like both ways and the tooling is great in Java to just make the API call like this.
you can mock the dependencies as well. for example, in your test file, you can write import org.springframework.boot.test.mock.mockito.MockBean; @MockBean MyService myService;
Hi I recently migrated to springboot 3.1.5. When I am modifying my existing test cases the way you have explained, I am getting Failed to load application context. Any suggestions? Thanks
difficult to say but most likely conflicting dependencies. You might need to look into making sure dependencies are compatible with your version of spring boot
Thank you for all the work you put into your videos 🙏❤
Hello! Thank you for video. Can you explain to me, why you use @MockBean instead of @Mock. Why we must to raise the Spring context in these tests ?
This isn't a unit test though. This is an implementation test, as you are acutally including API calls. A unit test would simply be testing the method on it's own, without using a restful API.
Ideally, one should have both unit and integration tests; after all, the unit test might pass as your method works as expected but your integration test might fail due to the path having changed - or an issue the other way around might arise.
I actually agree with this and I've wrote unit test using just the method. I like both ways and the tooling is great in Java to just make the API call like this.
Great help, thanks for the video!
No prob. Thank you for watching 👍
You are a savior man😁
Great explanation
Hi!
What if the controller has dependencias which depend on a service? How do I simulate that with Mockito?
Thanks!
you can mock the dependencies as well. for example, in your test file, you can write
import org.springframework.boot.test.mock.mockito.MockBean;
@MockBean
MyService myService;
Hi I recently migrated to springboot 3.1.5. When I am modifying my existing test cases the way you have explained, I am getting Failed to load application context. Any suggestions?
Thanks
difficult to say but most likely conflicting dependencies. You might need to look into making sure dependencies are compatible with your version of spring boot
Hi, were you able to solve the issue? If yes, then how?
does not recognize method content after contenttype and says i need requestbuilder before post? what do i do?
Is this still a unit test ? even though you use @Autowired and load the spring context ? Or is it an integration test ?
I asked myself this same question. Seems almost like both. TBH I liked it way more compared to traditional so I just went with it.
this video is just about typing.. too much typing.. that weird font in the board :/,
can I avoid controllers testing if I have Swagger in my dependencies?
If it’s a personal project, I’d say go for it. Maybe test the most important controllers to be cautious.
@@TeddySmithDev thanks for the answer buddy!
Your video is cool but work on the video quality on monitor
thanks for this video
No prob. Thank you for watching 👍