Spring Boot Unit Testing With Mockito - Controllers

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

ความคิดเห็น • 25

  • @franky3557
    @franky3557 ปีที่แล้ว +2

    Thank you for all the work you put into your videos 🙏❤

  • @Andrei-sc2mo
    @Andrei-sc2mo 9 หลายเดือนก่อน +3

    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 ?

  • @DesertCookie
    @DesertCookie ปีที่แล้ว +9

    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.

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว +5

      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.

  • @kacper9948
    @kacper9948 ปีที่แล้ว +1

    Great help, thanks for the video!

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว +1

      No prob. Thank you for watching 👍

  • @AronLangat-g1t
    @AronLangat-g1t 9 หลายเดือนก่อน

    You are a savior man😁

  • @codehustler8582
    @codehustler8582 ปีที่แล้ว +1

    Great explanation

  •  6 หลายเดือนก่อน

    Hi!
    What if the controller has dependencias which depend on a service? How do I simulate that with Mockito?
    Thanks!

    • @primegurjar
      @primegurjar 6 หลายเดือนก่อน +2

      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;

  • @TheShantanu30
    @TheShantanu30 ปีที่แล้ว +1

    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

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว

      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

    • @SouravDas-dm4dt
      @SouravDas-dm4dt 6 หลายเดือนก่อน

      Hi, were you able to solve the issue? If yes, then how?

  • @Sucheit
    @Sucheit ปีที่แล้ว

    does not recognize method content after contenttype and says i need requestbuilder before post? what do i do?

  • @choukri9421
    @choukri9421 9 หลายเดือนก่อน

    Is this still a unit test ? even though you use @Autowired and load the spring context ? Or is it an integration test ?

    • @TeddySmithDev
      @TeddySmithDev  9 หลายเดือนก่อน

      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.

  • @FiruzzZ-777
    @FiruzzZ-777 2 หลายเดือนก่อน +2

    this video is just about typing.. too much typing.. that weird font in the board :/,

  • @Lykkos-321
    @Lykkos-321 3 หลายเดือนก่อน

    can I avoid controllers testing if I have Swagger in my dependencies?

    • @TeddySmithDev
      @TeddySmithDev  3 หลายเดือนก่อน +1

      If it’s a personal project, I’d say go for it. Maybe test the most important controllers to be cautious.

    • @Lykkos-321
      @Lykkos-321 3 หลายเดือนก่อน

      @@TeddySmithDev thanks for the answer buddy!

  • @uyo-obongakpan9623
    @uyo-obongakpan9623 ปีที่แล้ว +2

    Your video is cool but work on the video quality on monitor

  • @slycreator
    @slycreator ปีที่แล้ว +1

    thanks for this video

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว +2

      No prob. Thank you for watching 👍