Spring Boot Unit Testing With Mockito - 1. First Unit Test

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ก.พ. 2025
  • Spring Boot Unit Testing - 1. First Unit Test
    Linkedin: / teddy-smith-015ba61a3
    Website: www.teddysmith.io
    Github: github.com/ted...

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

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

    Most underrated channel, the vast of many tutorial channels in youtube.

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

    I'm taking this course in a chill mood without anxiety because is from Teddy Smith, and I know I will ending up understanding all of it without any kind of stress, your previous tutorial of Spring Security helped me a lot!!

  • @house_d2024
    @house_d2024 ปีที่แล้ว +10

    Teddy you helped me a lot ! May God bless you

  • @siddharthvinze1276
    @siddharthvinze1276 5 หลายเดือนก่อน +1

    I was struggling to write test cases in junit. After watching your videos, it's a cake walk.
    Thanks a lot, you're really a great teacher.

  • @carrotblog1746
    @carrotblog1746 4 หลายเดือนก่อน

    Thank you so much I don't know where to start till I found you.

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

    Just wanted to add this in case you a newer developer that does not feel comfortable using git to time travel back before I wrote unit tests. Feel free to clone project and just delete Controller, Service, and Repository folders inside Test to follow along.

  • @shouvikxiv
    @shouvikxiv ปีที่แล้ว +4

    Loved it. We need more pee examples.

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

    If you are following TDD, should you write the tests out first before writing the code? Then change the code to pass the test as opposed to changing the test itself?

    • @ijazhaider6072
      @ijazhaider6072 8 หลายเดือนก่อน +1

      Provided that your test case has validated all business requirements and handled all edge cases. Then yes.

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

    Can you help me to solve this problems:
    - When I used 2 annotations the same as you: @DataJpaTest and @AutoConfigureTestDatabase, I got an error: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource. And I can't find any ways to fix it.
    - When I changed it to @SpringBootTest, everything works fine.
    Thank you for your help and answers.

  • @jasongoossens
    @jasongoossens 10 หลายเดือนก่อน +2

    Honest question: why are you testing JPARepository methods?
    Unless you have custom code in your repo's, wouldn't you skip that, and focus on the service and controller layers?
    (I assume you're mostly using the automagic methods, and not JPQL, or native SQL)

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน +2

      Yeah testing repository is overkill. But I notice that people are googling those keywords so need to include them from SEO standpoint. In real life I would concentrate all the tests in service + controller layer.

  • @Camupof
    @Camupof 11 หลายเดือนก่อน

    Thank you very much for your video. My tests are passing, but I'm getting the following warning: "Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended." While some sources say this is a non-critical error if the tests pass, others suggest otherwise. Should I be concerned?

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

      If I remember correctly, this same warning occurred in my terminal. If this isn’t for production app, I’d just let it go.

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 5 หลายเดือนก่อน

    Do we need to configure our H2 database by removing other database configuration for repository test case?

  • @smritagarg
    @smritagarg 7 หลายเดือนก่อน

    Why is the entity class is not identified in the reposoitory test class

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

    I run DDD, disaster driven development

    • @sneak9407
      @sneak9407 2 หลายเดือนก่อน

      You sir, are a D... diabolical 😂

  • @jackbaker995
    @jackbaker995 10 หลายเดือนก่อน

    the bladder example, lmao

  • @ShubhamSingh-xu3bo
    @ShubhamSingh-xu3bo 2 ปีที่แล้ว +2

    Could you please suggest any documentation why you have used @mockBean in ControllerTest and @Mock in service

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

      javarevisited.blogspot.com/2022/08/difference-between-mock-and-mockbean-in.html#axzz7msbBSJ6G The differences are very unclear and documentation is poor. My interpretation is that @MockBean provides Application Context, but I'm curious to those that think different.

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 5 หลายเดือนก่อน +1

    While using H2 for test case i am getting error of tables not found. Anyone has solved this then please help 😊.

  • @Lavless12
    @Lavless12 10 หลายเดือนก่อน

    Isn't Arrange Act Assert affiliated with TDD and Given When Then with BDD?

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

    Hi Teddy, good job and thank you for the tutorial, but i can not use the builder method in the PokemonRepositoryTests class even i added the @Builder in the pokemon model. do you have any explanation?

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

      Lombok installed? and you may need to install Lombok IntelliJ add on (sometimes it comes pre installed)

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

      @@TeddySmithDev first of all i am using Spring Tool Suite as IDE. and yes i have added the lombok dependency in my pom.xml and import the lombok.Builder in the Pokemon model. is there another step to complete?

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

      @@theodulesaintil5725 Lombok never worked for me too, I lost days trying to make it work, after exhausting all the possible options I don't use it anymore

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

    Which tool do you use for drawing schemes ? It's doesnt look like draw io or Excali.

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

      Microsoft whiteboard

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

      @@TeddySmithDev Thx a lot great content 🙏

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

    Does this also work if i use MySql as the Database in the main package?

  • @МаксимЯрема-е8щ
    @МаксимЯрема-е8щ ปีที่แล้ว

    Thanks for the tutorial. I noticed that the junit dependency is already present in the spring-boot-starter-test, so I guess there's no point in adding it again, right?

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

    Dude, say what you type, helps us follow along better.

  • @yesno5286
    @yesno5286 ปีที่แล้ว +3

    This topic should be a strand alone topic, and should be baby steps, i have a total of 45 min experience with testing and i cant follow along.

  • @NourWanis-b5x
    @NourWanis-b5x 11 หลายเดือนก่อน

    hello teddy , i have this problem : java.lang.NullPointerException: Cannot invoke "com.example1.pro.repository.GarageRepo.save(Object)" because "this.garageRepo" is null
    Can you please help me..

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

      You probably have a dependency injection issue. Make sure everything auto wired correct.