Test Driven Development (TDD) in Spring

Поделиться
HTML-код
  • Опубликовано: 26 сен 2024
  • In this tutorial we take a TDD approach to testing our REST Controllers in Spring Boot. We will build out a small application and focus on UNIT testing the controller. In this test we are mainly focused on the inputs and outputs of the REST Controller.
    🔗Resources & Links mentioned in this video:
    GitHub Repo: github.com/dan...
    👋🏻Connect with me:
    Website: www.danvega.dev
    Twitter: / therealdanvega
    Github: github.com/dan...
    LinkedIn: / danvega
    Newsletter: www.danvega.de...
    SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️

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

  • @gamires
    @gamires 4 месяца назад

    Beatiful way to explain TDD, write the application using it. Thank you very much Dan.

  • @dias6475
    @dias6475 Год назад +6

    Thank you, Dan, for this great content. I am looking forward to the next part, where you show us how the interplay between integration test and test container can be used. I love this channel. Thanks again.

  • @ElSrJuancho
    @ElSrJuancho Год назад +8

    I have learned a lot with your daily videos. You make me want to quit my Javascript job and look for a Java one , idk why.

    • @kagenashi2286
      @kagenashi2286 Год назад +6

      funny how we Java developers think the opposite, grass is always greener huh

    • @NotBjoggisAtAll
      @NotBjoggisAtAll Год назад +3

      ​@@kagenashi2286do we?😅

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

      Javascript is a pain in the ass dude!

    • @PapaFranciscoOk
      @PapaFranciscoOk 11 месяцев назад

      ​@@kagenashi2286talk for yourself, I worked with both and will always prefer Java instead of the hell of JavaScript haha

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

    Oh Yee, that is great.Although this is the right way First write a test then the code, but I don't do it. Either knowledge deficiencies or I am not so sure to do it.
    Thank you so much. I have learned a new technique today and you helped me a lot with this TDD. Thank you God bless you🙏

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

    LOL your timing on this video is AWESOME

  • @deepakvishwakarma193
    @deepakvishwakarma193 Год назад +1

    Thank you for TDD series

  • @claveralvaro6245
    @claveralvaro6245 9 месяцев назад

    Terrific Development with Dan, indeed

  • @OneClickLabs
    @OneClickLabs 7 месяцев назад

    This is a truly amazing video. Thanks Dan.

    • @DanVega
      @DanVega  7 месяцев назад

      I appreciate that! Thank you 🙏

  • @krlsdu
    @krlsdu 11 месяцев назад +1

    Thank you, I am learning a lot.
    I see some gaps in your round TDD, like the list of (improvements, issues, and smell code) that list is part of the concept of driving code to the next level.
    Another gap is the refactore in bove production code and test code because that can be aply when you repeat some parts of the test code, or for example, the moment you see the difficulty of isolating the test from de repository layer, when this issue pops up is a good time to try to refactor the code.

  • @bodo_Te
    @bodo_Te 5 месяцев назад +3

    The title is misleading: Dan shows some of the test-related features of Spring but that has nothing to do with actual TDD, is applies to just any automated test method. Dan mostly uses instead the "test last" method.

    • @UnMirloBlanco
      @UnMirloBlanco 4 месяца назад

      Right... the test requires a 2xx status code - let's setup the database 🙂

  • @sohaibelbokhari8319
    @sohaibelbokhari8319 4 месяца назад

    Great explanation, thaks a lot ❤🙂🙌

  • @rickhsieh85
    @rickhsieh85 7 месяцев назад

    Thanks for this tutorial ! awesome !

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

    The Ted Danson Placeholder Service

  • @Vanuatoo
    @Vanuatoo 6 месяцев назад

    In order to have maintainable tests, you should add additional layer which hides communication details of the REST client. Just introduce records to wrap the request and response and express the test semantics as plain as possible. Of course it adds time and complexity, but at the end it will help the team not to either create a mess in the tests or just abandon writing them. Also never use the objects (entity, dto) from the main code in your test, because if you change the JSON key name, effectively breaking the clients, tests will not catch that, because refactoring will rename everywhere.

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

    Great video, Dan.

  • @Alexander-vov
    @Alexander-vov 11 месяцев назад

    Big thanks for this tutorial

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

    Hi Dan! Wonderful tutorial. However I have to point out few things you did wrong. It has to do mostly with using Post record with POST & PUT. You should have used DTO instead, because you should not pass the ID of the Post in the request body, when you create or update. And since you are validating the records, it would fail if you tried to exclude them. Or at least it should fail - they should be mandatory :)
    Also you arbitrarily decided which attributes can be updated, which is not correct - in case of PUT, you update everything with the exception of an ID. If you do not provide new value, it is empty by default.
    Other than that - I have no objections - nicely done and I can not wait to see your next tutorial on integration / unit tests.
    P.S.: Just an idea - it would be great, if you could do the whole series on different types of tests - so for models / records, repositories, services, controllers, etc. Thanks!

    • @sergey--24
      @sergey--24 Год назад

      I guess @Id isn't supposed to be validated by @Valid - it's simply declaration that field is primary identifier.

    • @hesik3461
      @hesik3461 10 месяцев назад

      ​@@sergey--24You are right, @Id annotation comes from JPA and isn't related to dto validation. Validation annotations are the ones marked with @Constraint from jakarta.validation.
      But still the OP has a good point that id shouldn't be included in PUT nor POST requests. Dan probably knows that, but he did set a poor example by accident

    • @sergey--24
      @sergey--24 10 месяцев назад

      @@hesik3461 As far as I got it - Dan just wanted to avoid using the classic approach (DTO + Entity). He used just one data carrier - Post record, to show the new possibilities of using records in Spring Data JPA.
      Anyway, for PUT method id is required as path variable.
      And as we've already figured out - @Id fields aren't validated by applying @Valid annotation.
      So he could’ve left id field empty and put responsibility of identity generation on DB.

  • @scitechplusexplorer2484
    @scitechplusexplorer2484 11 месяцев назад +1

    Hey Dan, Amazing content. Learnt so much. Just wanted to know the IntelliJ theme u r using, it seems very soothing for eyes.

  • @MigOri-p1k
    @MigOri-p1k 11 месяцев назад

    Actually @Dan Vega, AutoConfigureMockMvc annotation is not necessary in order to use MockMvc. It's only when you want to do fine-grained configuration you'd need this.

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

    Dude, you are awesome.

  • @EdsonLima-hp6ew
    @EdsonLima-hp6ew Год назад

    I liked the theme, what is it? You could leave your setup settings fixed, it's irrelevant, but people like me like that. And congratulations on this beautiful video.

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

    Thanks alot for this. But they TDD is always seriously demanded where I currently live

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

    I like your videos and I have been following you since 2018. Your content quality has been going up a lot lately!!
    Regarding the topic, This is nice an all, but how do you approach TDD when you have a massive legacy app without tests and complex object(json) structures composed of quite a few objects, with a lot of db interactions (while many times you don’t have control over the db)..this is the truth most of the times in the java world. Don’t get me wrong, I love the video and thank you for the effort. I would like to see a more “realistic” approach, that’s all.cheers

  • @kensaitakeso
    @kensaitakeso 11 месяцев назад +2

    Hi Dan, I'm just wondering how Java and Spring are used in VMware. I always believed they use something low-level to achieve the best performance with virtual machines. Where does Java fit into all of this? :)

  • @IgorDomshchikov
    @IgorDomshchikov 3 месяца назад

    The comment about the epics, stories and features at ruclips.net/video/-H5sud1-K5A/видео.html is vital. Initially, I thought TDD was just about writing the test for your REST Controller methods, i.e, you are focused on writing tests for your methods first. But the idea of TDD is not testing a method but testing your system's behaviour/requirement/use cases.

  • @henriquebarros8303
    @henriquebarros8303 2 месяца назад

    Which theme do you used in the video?

  • @alexdev__
    @alexdev__ 6 месяцев назад +1

    Omg Dan... When I see you writing code... It's a beautiful experience, you do it with a lot of quality and wisdom. excellent video about TDD!

  • @wandacode
    @wandacode 11 месяцев назад

    37:58 It’s necessary to mock what repository returns when request body is invalid?

  • @petritoivari
    @petritoivari Год назад +1

    Haven't used java for some years (kotlin). Does anyone know why mockMvc and posts in PostControllerTest (at 18:23) are not private like they used to be? Allowing access outside the test class seems wrong.

    • @DanVega
      @DanVega  Год назад +3

      The default scope in Java is package / private so I'm allowing anything within the same package access to it. This isn't public.

  • @kelsonmenezes5560
    @kelsonmenezes5560 Год назад +1

    Hello Dan, congrats for the contents! This is very awesome.
    I'd like know what IDE is this?
    Thanks!

    • @shiddarthbista2248
      @shiddarthbista2248 Год назад +1

      intellij

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

      @@shiddarthbista2248
      Looks so different.
      Do you know the theme?

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

      @@kelsonmenezes5560 it's the new ui

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

      @@kelsonmenezes5560 vc soh precisa habilitar a nova UI. Settings > Appearance & Behavior > New UI > Enable new UI

    • @jarkow
      @jarkow Год назад +1

      @@kelsonmenezes5560 It's the New UI that you can enable in Intellij. Don't know about the font though.

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

    Do you know how to deploy spring boot 3 gradle project with wildfly?

  • @ХорхеРодригез
    @ХорхеРодригез Год назад

    Why Spring Data Jdbc and not Spring Data JPA?

  • @Robert-jo4ky
    @Robert-jo4ky Год назад +1

    what is the IDE name used in the tutorial?

  • @MarkMartin-k6s
    @MarkMartin-k6s 2 дня назад

    Walter Loaf

  • @mertbahadr7678
    @mertbahadr7678 11 месяцев назад

    shame on you forced test writer :)

  • @Harsh-fd4ml
    @Harsh-fd4ml 7 месяцев назад

    What's your IDE theme name

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

    what I like about hexagonal architecture is the ability to isolate your business logic and test it independently from the framework / DB.
    it can be pure java without any dependencies, so we can test the most important part of the app quickly and iterate faster!

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

    It was a great one Dan!! keep coming with it !!!!!

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

    The TDD mantra:
    Red -> Green -> Refactor!