JUnit Testing using Mockito and Power Mock - SpringBoot | JavaTechie

Поделиться
HTML-код
  • Опубликовано: 22 окт 2024

Комментарии • 94

  • @francksgenlecroyant
    @francksgenlecroyant Год назад +5

    Hi Bassant, 5 years later and this is still relevant 👊

  • @shiskeyoffles
    @shiskeyoffles 5 лет назад +8

    I am currently working in a company and my Job is to write unit test cases and this is really helpful. Thank you.

    • @Javatechie
      @Javatechie  5 лет назад +1

      Thanks Holmes,
      More test case video is on the way using rest assured and TestRestTemplate
      Will upload soon

  • @pratapsingh-le2br
    @pratapsingh-le2br 5 лет назад +7

    Really Help full to the interview prospective Thank' you Basant Bahi :) Great Effort Keep Going

  • @veenatiwari8621
    @veenatiwari8621 Год назад +2

    Thanks a lot sir for so knowledge video , kindly make a video for test case of predicate and specification.(dynamic query JPA criteria.

  • @sabakaiser4505
    @sabakaiser4505 5 лет назад +4

    This is a good tutorial to know how to use power mock, but before this if setup part is explained it will be helpful.

    • @Javatechie
      @Javatechie  5 лет назад +1

      Hi Saba , there is no additional set up as far I know , all required step I. Mentioned in video .
      Please do let me know anything else if I can help you

    • @TheTubepc
      @TheTubepc 2 года назад

      @@Javatechie if you can provide github link it will be useful

  • @chetanbhandari3033
    @chetanbhandari3033 4 года назад +3

    Hi awesome video and explained very well with use case pls.create multiple scenario and all junit and test case series which will help day to day programing

  • @literatebasics6305
    @literatebasics6305 5 лет назад +5

    Good video. Worth watching. Can you please do more videos on Power Mockito ?

  • @mukundpatel1768
    @mukundpatel1768 4 года назад +2

    Very nicely explained. I have used your way and implemented unit test ... Thanks

  • @shivakamlikar2144
    @shivakamlikar2144 5 лет назад +1

    I am very happy..... Your explanation is awesome and very helpfull for development

    • @Javatechie
      @Javatechie  5 лет назад

      Thanks dude , keep watching

  • @rameshchowdarykonka5551
    @rameshchowdarykonka5551 5 лет назад +4

    Tq.. Just now i am searching for........Again Tq........

  • @shalinishalu3465
    @shalinishalu3465 3 года назад +1

    Great. . really helpful. Thanku

  • @blaxminarayanpatra7311
    @blaxminarayanpatra7311 4 года назад +1

    Hi Bro, Suppose I have one method inside multiple private methods inside each method have multiple methods in that case should I maintain test case for all method or I will ignore (In realtime) Thanks In advance.

    • @Javatechie
      @Javatechie  4 года назад

      No we should ignore only for actual business you need to write one positive and one negative scenario

  • @hiteshupreti4250
    @hiteshupreti4250 3 года назад +1

    why we are using "spy" for private and final methods??

  • @rahimkhan-fh9dd
    @rahimkhan-fh9dd 5 лет назад +1

    tutorial was more helpful,
    Can we use mock instead of spy in private method like PowerMockito.mock()?

  • @javadream6085
    @javadream6085 3 года назад +1

    Do you know how to debug this test cases using powermock. Because i am trying to debug this but all my endpoints are skipped. Same is working fine with mockito but with poermock i am not able to debug.

    • @Javatechie
      @Javatechie  3 года назад

      Debugger should work for any implementation let me check

  • @gaurav16413
    @gaurav16413 4 года назад +1

    Great Tutorial Sir..

  • @dattun976
    @dattun976 5 лет назад +1

    HI bro, Code coverage is showing 0 % when I use powermockito to run test cases. even I've tried to run your example but still showing 0% as code coverage. do we need to do any changes in configuration? if yes.. please reply ..

    • @Javatechie
      @Javatechie  5 лет назад

      There is some issue with power mock and code coverage , I already reported a bug for it ...once I will get updates will let you know ok

    • @dattun976
      @dattun976 5 лет назад +1

      @@Javatechie thank u bro for the reply :)

  • @pviswatmula
    @pviswatmula 4 года назад +2

    In the addDiscount method, you are setting discount amount to price when the price is less than or equal to 1000. Should n't the discount amount be zero though.

    • @Javatechie
      @Javatechie  4 года назад

      Yup you could add that

    • @pviswatmula
      @pviswatmula 4 года назад

      @@Javatechie Nice tutorial except the logical error. Do you really want to give 100% discount when price is less than or equal to 1000?

  • @shanmugapriya3762
    @shanmugapriya3762 4 года назад

    I want to access static method so I used powermockrunner class..while executing test case I'm getting like initialisation error.do I needs to add any configuration?.how to solve?

  • @shivakamlikar2144
    @shivakamlikar2144 5 лет назад +2

    Bro... You can upload spring batch related junit test cases with power Mockoto

    • @Javatechie
      @Javatechie  5 лет назад

      I don't think we need to write test case for spring batch With power mock
      You can go for mockito by mocking batch service

  • @o7n71a0453
    @o7n71a0453 Год назад

    But in code coverage the private method lines will still not get covered right

  • @dattun976
    @dattun976 5 лет назад +1

    hi bro, nice tutorial... can we do testing for inner class ? and also how to test lambda expression code ?

    • @Javatechie
      @Javatechie  5 лет назад

      We are writing test case for outer class right so inner class will be execute by any member from outer class .
      So I don't think we need to write test case for it .but yes if you want to achieve code coverage then you must have to cover test case for it .

    • @dattun976
      @dattun976 5 лет назад

      @@Javatechie I'm trying to cover the inner class while testing one service layer method,but the problem here is, Mockito is not covering the inner class code and simply it is skipping that inner class code .kindly suggest a way to solve this issue. and Thank u v much for the reply.

    • @Javatechie
      @Javatechie  5 лет назад

      Dattu I will check and update soon

    • @dattun976
      @dattun976 5 лет назад

      @@Javatechie Thank u :)

  • @shaikshasayyad131
    @shaikshasayyad131 5 лет назад +2

    Could you please upload a complete spring boot-microservices application?

    • @Javatechie
      @Javatechie  5 лет назад

      Yeah am planning to do that but before that I would suggest you to go through all spring Boot video where I explained each component of microservice like Eureka,zuul, hystrix etc...

    • @shaikshasayyad131
      @shaikshasayyad131 5 лет назад +1

      I've completed watching them. I'm eager to see the complete microservice application.
      Thanks for a quick reply

    • @Javatechie
      @Javatechie  5 лет назад

      @@shaikshasayyad131 cool will do soon

  • @manishnegi2882
    @manishnegi2882 3 года назад +1

    could you please share the dependency version that you used I got the exception "Class not prepared"

    • @Javatechie
      @Javatechie  3 года назад

      Please check source code link in video description

  • @sureshdhulipudi600
    @sureshdhulipudi600 4 года назад +1

    How to write power mockito for private methods and After writing unit test cases if we click "Coverage As" it should cover those private methods as well.
    thanks in advance :)

    • @Javatechie
      @Javatechie  4 года назад

      Power mockito won't provide you mechanism for coverage
      You need to use Jacoco for coverage

    • @sureshdhulipudi600
      @sureshdhulipudi600 4 года назад

      @@Javatechie, without any errors, test cases are executing but coverage is not happening for private methods in both IDE and Jacoco report.

    • @sureshdhulipudi600
      @sureshdhulipudi600 4 года назад

      we are using activiti bpm with spring boot in our project, so there only protected methods in those classes, that methods directly call by activiti bpm.

  • @salamomran1507
    @salamomran1507 4 года назад +1

    thank you sooo much

  • @amargupta1728
    @amargupta1728 4 года назад

    Nice but How can we run Power Mock with spring boot 2.3 and mockito? @RunWith is not available with Boot 2.3 so please suggest

    • @Javatechie
      @Javatechie  4 года назад +1

      You can directly run using @SpringBootTesr

    • @amargupta1728
      @amargupta1728 4 года назад

      @@Javatechie I tried but didn't get PowerMockito and its helper classes

  • @Deepika_Durairaj
    @Deepika_Durairaj 5 месяцев назад

    Can I use powermock with java 17?

  • @brianspinos
    @brianspinos 4 года назад +1

    What are the dependencies (with versions) ?

  • @ravishakya8605
    @ravishakya8605 4 года назад

    Hi, Can you suggest how to write test cases for protected method?

  • @PankajKumar-qk8oh
    @PankajKumar-qk8oh 4 года назад +1

    Helpful video👍

  • @MrMadhavsai
    @MrMadhavsai 5 лет назад +1

    great explanation bro

  • @saktiranjanbehera7010
    @saktiranjanbehera7010 2 года назад

    Thanks Bhai

  • @aditigupta6870
    @aditigupta6870 Год назад

    Is there a need to write init method here? You are doing mockinits on NotificationService class but there is no mock intialisations there, so what is the need of doing this?

    • @Javatechie
      @Javatechie  Год назад

      Yes it requires only if you want to pre initialize something

  • @architbaba1
    @architbaba1 Год назад

    Please autowire some class and give example for complex

  • @subhojit1741984
    @subhojit1741984 Год назад

    Hi,I am getting error "java.lang.reflect.InaccessibleObjectException: Unable to make protected void java.lang.Object.finalize() throws java.lang.Throwable accessible: module java.base does not "opens java.lang" to unnamed module" while running in Intellij IDE.Kindly help

    • @AishwaryaB-t2i
      @AishwaryaB-t2i Год назад

      Have you resolved it? Even I am getting the same error

  • @トゥアンファム
    @トゥアンファム 2 года назад

    how to mock final class using power mock-api, bro?

  • @CodeWithJava114
    @CodeWithJava114 2 года назад

    getting error that "Failed to find the modifires field in method setInternalstate " pleae help

  • @nikhilraj9524
    @nikhilraj9524 2 года назад

    I stuck because after using powermock also private method is being called.

  • @sushilkumarpandeypandey1087
    @sushilkumarpandeypandey1087 5 лет назад +1

    why @InjectMocks is used why not @Autowired ?

    • @Javatechie
      @Javatechie  5 лет назад +1

      @,Autowired will create a new object where injectMock will give u proxy object instead of actual object

    • @sushilkumarpandeypandey1087
      @sushilkumarpandeypandey1087 5 лет назад

      can u explain the difference between proxy object and mock object

    • @Javatechie
      @Javatechie  5 лет назад

      Mock object means proxy object

    • @sushilkumarpandeypandey1087
      @sushilkumarpandeypandey1087 5 лет назад

      that means instead of @InjectMocks we can simply use @Mock also

  • @maheswarareddy6783
    @maheswarareddy6783 5 лет назад

    when we should use fail() method in JUnit testing

  • @sairamreddy500
    @sairamreddy500 2 года назад +1

    Can we mock enum methods?

    • @Javatechie
      @Javatechie  2 года назад

      Yes we can

    • @sairamreddy500
      @sairamreddy500 2 года назад

      Thank you for confirmation. Could you plz provide short video or code sample on it.

  • @SHIVAMSRIVASTAVSIEC
    @SHIVAMSRIVASTAVSIEC 2 года назад

    I am getting unrooted test error please help me

  • @salauddinansari2072
    @salauddinansari2072 5 лет назад +1

    Hello, Sir, I want to learn SpringBoot step by step please help me

    • @Javatechie
      @Javatechie  5 лет назад

      Yeah sure please let me know your doubts

    • @salauddinansari2072
      @salauddinansari2072 5 лет назад +1

      thanks for your reply. I'm a beginner but already know about Core java servlet. No doubt any but i want to know how to make a project using spring-boot and java

    • @Javatechie
      @Javatechie  5 лет назад

      I would suggest you to learn spring first before moving forward to spring boot

  • @saketkumar6671
    @saketkumar6671 2 года назад +1

    Code is Not visible

    • @Javatechie
      @Javatechie  2 года назад

      Where in video or in git ?

  • @kuldeepmishra7889
    @kuldeepmishra7889 5 лет назад +1

    Visibility is not clear

    • @Javatechie
      @Javatechie  5 лет назад

      Kuldeep video resolution is 1080 HD
      Please check your internet connection ,if it is not strong then default it will play on 360 resolution.
      So try with good internet connection

  • @swadhin1985
    @swadhin1985 4 года назад +1

    You are uploading video on youtube, but you don't know pom is very importing, you are not showing pom files, so this is not informative

    • @Javatechie
      @Javatechie  4 года назад

      Yes I agreed Going forward I will show pom

    • @swadhin1985
      @swadhin1985 4 года назад

      @@Javatechie Can you please upload a single video on spring boot, junit, mockito and power mockito with details pom, I hove you will upload thanks in advance