Testing and Refactoring Legacy Code

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

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

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

    The way it is explained in incremental, step-by-step order makes this video feels smooth, easy to follow, and beginner friendly. Even though it's already 8 years old, it's one of the best refactoring video around. Thanks a lot sir!

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

      I wish someone showed me this 9 years ago, I would have kept so many legacy code revamp jobs that I attempted and failed

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

    Finally a testing video showing ACTUAL testing in real life. Instead of in a pristine, best-case-scenario where there are zero dependencies and oooh ‘magically the only thing that needs to be tested are pure functions’.

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

      Yes
      This kind of thing is still not taught in any school

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

    What one learns from this video is what beginners learn after years of experience. Thank you very much for this video... Truely grateful.

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

    Definitely one of the best videos about testing and refactoring, thank you !

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

    0:50 Legacy code rule
    1:18 Tips:
    - Start testing from shortest branch to deepest branch.
    - Start refactoring from deepest branch to shortest branch.
    6:02: Tip for testing with outside (cannot mock) dependence.
    57:20 Refactoring static method.

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

    Definitely one of the best videos about testing and refactoring.

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

    This is a really fantastic video. I am C# developer and I was still able to follow along perfectly and learn SO much. Thanks so much for sharing this, you should be proud!

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

      +Samantha Webb agreed, this helped me so much in getting a feel for how to deal with legacy code and how to design my tests in general!

    • @esjihn
      @esjihn 6 ปีที่แล้ว

      I also agree. I got a SDE job and my first project is refactoring a massive program with hundreds of classes partially in C# and VB. I had no idea where to start and there are code smells all over. This video has helped me tremendously by applying the same concepts

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

    Here is the Github repository: github.com/sandromancuso/trip-service-kata
    Feel free to clone and play with it. :)
    When you do, push your solution to your own Github and send us the link adding a comment here. I would love to see different solutions and approaches to it.
    Thanks for watching the video.

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

    Absolutely. Both PowerMock and JMockit are an alternative. I, personally, discourage the use of both since they allow us to test things we should not be testing, like private methods and other internals. Since they make testing legacy code easier, developers are less inclined to see the issues the code really has. Some people use the expression "listening to our tests". Basically, what it means is if it is too difficult to test, almost always is because the code is not good enough.

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

    There's not many refactoring tutorials as good as this! Thx.

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

    Very good video on writing clean code with refactoring. I liked the various shortcuts you used as well. Almost a putting it all together kind. Thanks for sharing!

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

    Thank you very much for this in-depth refactoring work! Very specific and practical examples with general and powerful techniques. I certainly learned a lot seeing you in action!

  • @zedisdeadz
    @zedisdeadz 6 ปีที่แล้ว +15

    6:55 the seam technique is so good. actually solves 90% of the legacy code testability issues :D

    • @PuerinTheHunter
      @PuerinTheHunter 5 ปีที่แล้ว

      Thanks for calling attention to that one! It is really useful.

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

      Feels a bit like test induced damage to introduce inheritance like that, but you can always refactor it later, I guess

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

      @@PlerbyMcFlerb It's called "Extract And Override" and is one of the techniques to create a seam taught by Michael Feathers in his book "Working Effectively with Legacy Code". If you were starting from scratch you'd likely be using dependency injection but since that's breaking the public interface and having to update lots of classes just to make it compile again, it's way better to use E&O.

    • @alexsmart2612
      @alexsmart2612 2 ปีที่แล้ว

      Except now you are not testing how your class is interacting with its collaborators at all. You could replace getLoggedInUser() implementation with throw Unimplemented() and your tests will still be all green.

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

    Finally took the time to do this kata. It's great to see your pov afterwards. Thanks for sharing!

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

    This was an exceptionally insightful and helpful video. I've been trying to teach myself good TDD recently, and one of my big hurdles has been dealing with legacy code (the other being figuring out how to begin testing MVC frameworks). Subscribed and I will be ordering your book. Thank you again for your excellent tutorial!

  • @caneesh
    @caneesh 7 ปีที่แล้ว

    Thank you for publishing this video. This is an asset to the world, because it teaches developers to write good quality code. Publish other videos addressing different challenges, its a great social service

  • @abhilashmaipady4081
    @abhilashmaipady4081 2 ปีที่แล้ว

    Such a great tutorial. Explained all the basics about the unit testing. Expecting these kind of videos again.

    • @SandroMancuso
      @SandroMancuso  2 ปีที่แล้ว

      Thanks, Abhilash. You might want to look at our Codurance channel. All new videos are there. th-cam.com/users/codurance

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

    Very good insights on how to deal with coupled legacy code, thanks man! 👏👏

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

    I really enjoyed this video. Your experience shines through in even the smallest change you perform - even choosing the most expressive method names is an art that takes a long time to perfect. This is going to help me a lot at my current task at work! My favourite bit was your test naming convention.

  • @HansLowell
    @HansLowell 11 หลายเดือนก่อน +1

    Feel like ive been searching for this since forever

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

    It was pleasure to see. Very informative and practical. Thank you!

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

    The last step, where I include Spring, was just a demonstration of what you can do in case you are already using Spring. I found it useful to add to the exercise since the vast majority of the Java projects use it.
    I just wanted to show how you can make Mockito work with the Spring @Autowired annotation. You can ignore the last step if you don't use Spring. An alternative would be to pass the TripDAO to the TripService constructor, in case you want to do dependency injection by hand.

  • @SandroMancuso
    @SandroMancuso  11 ปีที่แล้ว

    I cannot add links to the comments. The TH-cam link above does not work. Search on TH-cam for Johan Martinsson "A few general tricks for simplifying conditional logic"

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

    I have not seen any other video which is as good as this one. Great. Cast more of these pls.

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

    It is awesome this way! Thank you so much.
    The tips you have given are great to start refactoring the legacy code and write UT.
    => Start testing from shortest branch to deepest branch.
    => Start refactoring from deepest branch to shortest branch
    Q1: should we more focus on loosely couple architecture and avoid static methods so that we can mock the dependencies?

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

    Here are a few more videos, some by my colleagues, some by me. : codurance.com/publications/videos/

  • @sbern714
    @sbern714 9 ปีที่แล้ว

    My compliments! A very useful tutorial, and it's a joy to watch you code.

  • @Artoooooor
    @Artoooooor 4 ปีที่แล้ว

    Thank you. I deal with the legacy code quite often and I think I will find this lesson useful.

  • @christofferklang
    @christofferklang 11 ปีที่แล้ว

    Reallt good video. Immediately adopted your naming scheme for tests, great solution to what I was missing most coming to Java from RSpec (the descriptions).
    Hope to see more videos in the future. Thanks alot.

  • @suckyboy
    @suckyboy 6 ปีที่แล้ว +8

    Thank you so much for the video. I think you just got me a new job

  • @SandroMancuso
    @SandroMancuso  11 ปีที่แล้ว

    Thanks Christoffer. Anyone coming from RSpec will definitely find the Java testing frameworks a little bit clunky. But with a few tweaks here and there we can make it look OK. A common alternative is to write the tests using Spock. I'm glad you liked the video.

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

    Truly a great video. Some very simple but powerful techniques that have helped me refactor any code base not just a Java application. Thank you Sandro for a great tutorial!

  • @MehdiOkhovat-pf6fd
    @MehdiOkhovat-pf6fd ปีที่แล้ว +1

    finally a practical refactoring example, thank you very much. but I have a question. I think there was a better work around for isolating TripDAO static class. you could define an non static adapter class for it then wrap it, afterwards you could extract an interface from the wrapper class and inject it through TripService constructor.

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

      Thank you. Glad you liked it. The approach you suggested would certainly work, mainly if you really don't want or cannot change the TripDAO. I found it simpler just to add an instance method that uses the static. This way I can inject and mock the DAO, using the instance method instead. And if one day, all the references to the DAO are using the instance method, I could kill the static. Just a matter of preference. But both solutions would work fine.

  • @SandroMancuso
    @SandroMancuso  11 ปีที่แล้ว

    I just added the link on the description of the video. TH-cam doesn't allow me to add links when posting a comment.

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

    You win my like, it's an excellent video. I look forward to seeing the next videos.

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

    Very good video, thank you kind Sir.

  • @maurihb
    @maurihb 11 ปีที่แล้ว

    Amazing video, as a not so experienced developer, I've been watching several talks of the theory behind all these, but finally watching it in action is very very helpful.
    Hope you continue making these screen casts.
    Could you recommend me some books/sites about:
    1) General IDE/Frameworks tips/tricks to improve productivity
    2) Java design patterns and taking advantage of the features of the language (as you did with your builder, and the addFriends(User... users) example)
    3) Re-factoring/Testing

  • @kke
    @kke 11 ปีที่แล้ว

    Paused to check if the noise is from your CPU fan or mine :) Great video.

  • @odiernod
    @odiernod 11 ปีที่แล้ว

    Questo video è davvero fantastico, complimenti! Riesci a spiegare in un modo chiaro è semplice come si può, in effetti, rendere "testabile" un'applicazione "legacy". Lo faccio vedere a tutti i miei colleghi.

  • @rogerioliesenfeld9042
    @rogerioliesenfeld9042 12 ปีที่แล้ว

    An alternative is to use a mocking tool when writing the tests. PowerMock and JMockit are two such tools which allow the creation of unit tests without first changing the code to be tested, even if it calls static methods.

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

    Thank you so much! Great and very inform video. I'm new to Unit-Testing (C#) and this video is very helpful.

  • @enricjaen3174
    @enricjaen3174 11 ปีที่แล้ว

    It would be nice if Sandro allowed others to modify his git code so people with further ideas like you could continue the refactoring.

  • @VishalKotecha91
    @VishalKotecha91 10 ปีที่แล้ว

    It was awesome that way! Thank u so much for the wonderful session! *Appreciation*

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

    Such a great lesson!!! thanks Sandro!!!!

  • @7thAttempt
    @7thAttempt 10 ปีที่แล้ว

    Bravo! Thank you for taking the time to make this excellent video!

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

    What a beautyful piece of code! It was like whatching a paiting, enjoyable

  • @manor1730
    @manor1730 6 ปีที่แล้ว

    Wow, great video even in 2018! Helped me understand some things I had been wondering about.

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

    great movie, you should do more !
    I really enjoyed it.

  • @surendermca
    @surendermca 10 ปีที่แล้ว

    excellent demo with real time code refactoring!

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

    really good thanks a lot , how are you running "code coverage" command in elipse?

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

    This was fantastic! I really did learn a lot.

  • @Mohamed-uf5jh
    @Mohamed-uf5jh 4 ปีที่แล้ว +1

    Just excellent ! a good job

  • @elfoxini
    @elfoxini 3 ปีที่แล้ว

    This was eye-opening for me, thanks

  • @nickbarton3191
    @nickbarton3191 2 ปีที่แล้ว

    Excellent.
    Shorter to deepest path.
    Any recommendations as to hierarchy order ? Bottom up ?

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

    best cast i seen about this topic

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

    Incredibly well done. Thanks so much for the effort.
    Feel free to do more!

  • @SandroMancuso
    @SandroMancuso  12 ปีที่แล้ว

    Thanks Johannes
    You are absolutely right. I totally forgot to refactor the ArrayList and use the Collections.emptyList() instead.

  • @AishwarMuthuraman
    @AishwarMuthuraman 10 ปีที่แล้ว

    Great video on refactoring legacy code.

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

    Second time to review. It is an awesome tutorial.

  • @paulmudondo1041
    @paulmudondo1041 9 ปีที่แล้ว

    very well thought of and presented..

  • @CharleyDC5R
    @CharleyDC5R 8 ปีที่แล้ว

    Masterpiece. Sharing this with all my team. Thank you Sandro!

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

    Sandro, it was very very nice! I'll be brave now. =) And your kata is a nice subject for a dojo. Abraão Alves Nelson Eldoro

  • @saqibsaud9570
    @saqibsaud9570 8 ปีที่แล้ว

    Thank you, this video basically answered all my question.

  • @myhimalayanchants
    @myhimalayanchants 9 ปีที่แล้ว

    Yes this well though but why are we introducing auto wiring in production code ?
    This will change the start up behaviour ?

  • @gehbittedasgibtsned
    @gehbittedasgibtsned 3 ปีที่แล้ว

    very nice test driven development

  • @pierre-jeanmartin5621
    @pierre-jeanmartin5621 5 ปีที่แล้ว +1

    As many likes as subscribers, but you deserve more

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

    Very good video! it was very inspiring and i enjoyed it a lot. thanks!

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

    Thanks for the presentation!

  • @sheljagupta1355
    @sheljagupta1355 7 ปีที่แล้ว

    Sir will you please upload more videos explaining the refactoring and testing of legacy code...
    It will be very hepful for us....
    Thanks for uploading this video.
    Its a request to plz upload more videos and practical explanation on refactoring...

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

      Thank you for watching. There are a few more videos here: codurance.com/publications/videos/

  • @sathishkumarshanmugavel673
    @sathishkumarshanmugavel673 10 ปีที่แล้ว

    Good session. Very useful. Thanks a lot.

  • @FranklinRibeiro
    @FranklinRibeiro 11 ปีที่แล้ว

    Initially, I thought "One hour and seventeen min?! No way!". One hour and seventeen minutes later... "Already over? Do not stop!" :)

  • @KIRGOV
    @KIRGOV 8 ปีที่แล้ว

    Wooow lovely thanks a lot Sandro for this video
    I'll definitely give your video as food for thought and action to my team =)

  • @LittleBobbyHasTables
    @LittleBobbyHasTables 11 ปีที่แล้ว

    Thank you very much for this awesome demonstration!!!

  • @rockYhre
    @rockYhre 11 ปีที่แล้ว

    Great video, thanks for sharing. Can you post some additional refactoring resources you recommend?

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

    Awesome tutorial. Thank you!

  • @kwanjason4709
    @kwanjason4709 4 ปีที่แล้ว

    this video is great ! however the last part of TripDao static to instance will break the function even it pass the test. It need to be initialize somewhere

  • @afshinsamia3328
    @afshinsamia3328 9 ปีที่แล้ว

    Thanks for this great video! learned a lot!

  • @safajasim
    @safajasim 8 ปีที่แล้ว

    Great video ... thank you for sharing

  • @PiotrKosmowski
    @PiotrKosmowski 12 ปีที่แล้ว

    Thank you. Piece of really good job.

  • @mrdeetal
    @mrdeetal 11 ปีที่แล้ว

    Awesome video, do you plan on making any more videos like this one?

  • @LuigiAntonini
    @LuigiAntonini 11 ปีที่แล้ว

    Very very good video! Thank you!

  • @enricjaen3174
    @enricjaen3174 11 ปีที่แล้ว

    Excellent refactoring, but refactoring it's still incomplete because by including Spring you are going beyond unit testing. In a real project, without Spring you would need to configure the project to use Spring, and so to do acceptance tests to verify that injection is working.

  • @rikardsoderstrom835
    @rikardsoderstrom835 2 ปีที่แล้ว

    Sadly you broke your "production code" in this video :( When moving the use of a global variable into your members argument list you cannot replace its default value with null all over the code base like that. It must be replaced with the value it had before you made it an argument, which in this case would be the global variable call. Yes it would stick in peoples eyes but it would be very visible everywhere that this global is now used as an argument, which would make it easy to fix when those other parts of code is to be updated.
    Anyways, keep up the good work :)

  • @whatisthisnote
    @whatisthisnote 12 ปีที่แล้ว

    Enjoyed watching this!

  •  8 ปีที่แล้ว

    Is the @Spy useful?
    I don't think so and I heard it's a bad habit to use @Spy.

  • @SangpilBYUN
    @SangpilBYUN 12 ปีที่แล้ว

    Thank you.! I have learned from this video too much.

  • @alexsmart2612
    @alexsmart2612 2 ปีที่แล้ว

    What should I do if I have been refactoring for thirty minutes, getting green every time and suddenly realize that I have been running the wrong test suite the entire time?

  • @SpiritOfIndiaaa
    @SpiritOfIndiaaa 4 ปีที่แล้ว

    how are you copying/moving data from one block to another @15:00??

  • @ashisha2z
    @ashisha2z 12 ปีที่แล้ว

    Thanks a lot for sharing this. Cheers

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

    34:03
    I still don't get it why tripBy is the deepest code in the function instead of that for loop?
    Did i missed something in the video?
    Can anyone help me😅
    Or maybe branch means if/switch case?

  • @myhimalayanchants
    @myhimalayanchants 9 ปีที่แล้ว

    Are we forcing Spring to inject the Dao during start and How are we sure that this will not break anywhere else ?

    • @SankarV
      @SankarV 6 ปีที่แล้ว

      That DAO literally has a static method. So he knows it won't break anything

  • @hichamouchker
    @hichamouchker 10 ปีที่แล้ว

    Thank you alot for this interesting tuto.. :-)

  • @tomaspyth7017
    @tomaspyth7017 5 ปีที่แล้ว

    Could someone please explain why by the time: 23:27 the lines 35 and 37 are marked *RED* in the *TripServiceTest.java*
    Thanks in advance for taking the time and thinking about it
    Awesome video by the way. Top knowledge in short time 👍👍👍

  • @eNSWE
    @eNSWE 8 ปีที่แล้ว

    I would probably have preferred passing some sort of interface that exposes a method for getting the logged in user, rather than passing a user and just hoping that people read the name of the parameter.
    might not be completely necessary, but to me it communicates intent more if you ask for a provider os the logged in user, rather than asking for a user and saying "ps please make sure it's the logged in one". it makes it harder to write wrong code.

  • @SandroMancuso
    @SandroMancuso  12 ปีที่แล้ว

    My pleasure. Thanks.

  • @AntinKrauss
    @AntinKrauss 11 ปีที่แล้ว

    Really good video.

  • @kameit00
    @kameit00 11 ปีที่แล้ว

    Thank you for this video. Just thank you...

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

    13:09 audio clears up

  • @yuskamify
    @yuskamify 10 ปีที่แล้ว

    Great video..
    Thanks a lot Sir

  • @realdn
    @realdn 11 ปีที่แล้ว

    Great video! Thanks a lot :)