Java Unit Testing with JUnit - Tutorial - How to Create And Use Unit Tests

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

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

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

    Hey John! I took a course in the fundamentals of computer science last year where our professor mentioned the importance of unit testing and made us all write our own ones without really explaining the reason why or showing how to properly do it. This video really cleared that up for me. Thank you so much!

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

    I'm really thankful to you. I'm currently in the process of studying. And I researched it because my doctor didn't talk about it and I found a similarity between it and the Java language, but it's not a regular Java, it's a test for Java. Thank you. I really understand. And of course I'm proud of myself because I researched who you might laugh at. But that's true. Thank you again❤

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

    Hi John, thanks for the video. I have to write my own unit tests for a project assignment, but have never done or got properly shown how to. This video cleared all my questions.

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

    I've always been scared of Testing, thanks to this video, I feel quite comfortable with it now.

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

    I have been watching since a year. Your videos are very simple to understand. Thank you.

  • @Roberto-oz6et
    @Roberto-oz6et 2 ปีที่แล้ว +295

    Your channel is pure GOLD! I'm learning more in a few minutes than an whole semester of classes.

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

    needed a refresher as i apply to sdet jobs. excellent clear stuff. thanks.

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

    Master of coding 🙌 👏

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

    whenever you have covered a topic, you have become my go-to guy to learn new things. It would be awesome if you covered mocking frameworks as well like Mockito which are probably unavoidable for a developer.

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

    Just want to say these videos are great and such amazing quality. I would definitely pay for a data structures and algorithm course after completing the Java course.

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

    Exactly what I need at my level. I'm at the point where I can make my own software, but my code is all spaghetti and it takes a while to debug. Now I'm going to get into the habit of testing it early and often.

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

    You are great John ! I really enjoy your videos, they are so practical but with a lot of useful information and knowledge. You do that complex topic looks really easy and funny. Keep with this awesome work. Thank you !

  • @AkshayDubey-fj7zj
    @AkshayDubey-fj7zj ปีที่แล้ว

    Thanks a lot!. I wish you could create a video on Unit Testing for Spring Boot Application as well in near future

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

    Awesome overview and introduction to JUnit, thanks!

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

    Appreciate you and this channel ... would love to see you cover mockito!

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

    very good explanation , I will use more and more unit test

  • @ajithak.s.5224
    @ajithak.s.5224 2 ปีที่แล้ว +2

    Simple and precise illustration. Thank you John. Probably including parametrized junits supported in Junit5 would be better.

  • @bbaekkhyyunne_4750
    @bbaekkhyyunne_4750 8 หลายเดือนก่อน

    very clear with thinking procedures

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

    Hey John, kindly make one session for Intellij ide usage for java and maven plugin nd other which will make code coverage

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

    John you are the best of the best. Keep it up and would like to see some Spring boot tutorials. Many Thanks

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

    Great intro to unit testing John, awesome! Thanks!

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

    I was so great ful for born in this era.

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

    Hey brother, your explanation is good! keep it

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

    That was excellent, love your tutorials!

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

    Thank you Lex Luthor of Java language ❤️

  • @MY-rl6pv
    @MY-rl6pv 6 หลายเดือนก่อน

    I wish you had a full spring boot tutorial course

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

    Thank you John, much appreciated!❤

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

    Love your content! Keep on, John!

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

    super awesome explanation

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

    This video is amazing! Thank you so much for sharing!

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

    thank you for this awesome informative content! Learned a lot! Cheers buddy

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

    Very well explained..Thank you so deeply... 😊

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

    Hey John, Thanks for your great work. Your content and explaination is exemplary

  • @AbhishekJaiswal-p1u
    @AbhishekJaiswal-p1u ปีที่แล้ว

    Hi John, you have not written test for the input number greater than 100 which should return invalid value but in the above code it would return an 'A'

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

    Extremely helpful. Thanks.

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

    thanks John, can you make videos of Junit with mocktio or any mocking framework

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

    I'm loving your channel! I'm a teacher, and we do a lot of writing in the main method (at least at the beginning of the year. How would I test a certain output of the main method. And how can I test to make sure they used a print vs printf vs println in their code?

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

    Hi John, Which is a better IDE Eclipse or IntelliJ? Please let me know when you get a chance.

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

    Bro you are the best

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

    Hey John, cool u please cover Dependency Management using Maven (pom) and Gradle in depth video. Thanks

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

    excellent John, can you record about Mockito

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

    Thank you so much 👏👏

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

    Excellent 👍

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

    Thank you soooooo so so!!!

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

    Thank you so much!

  • @GabrielSoares-mt5il
    @GabrielSoares-mt5il 3 หลายเดือนก่อน

    Great video.

  • @Johnny-tz2dx
    @Johnny-tz2dx 2 ปีที่แล้ว

    Your videos are amazing!! I wonder if you would decide to tackle the module-info files. Will look forward to them!!

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

    Thank you!!

  • @abbasabdulsalambamidele8760
    @abbasabdulsalambamidele8760 8 หลายเดือนก่อน

    Thank you.

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

    I need to know about Mocks, or more complicated tests. For example: i need to test a method that doesn't return anything.

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

    So I guess you create a test class for testing each method. That would mean a lot of test classes would be created for the entire module.

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

    Hey john could you please enable the captions for this video....?

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

      Hmm they should be working fine, I'm able to see the auto-generated captions when I view the video.
      Anyone else having this issue?

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

      @@CodingWithJohn now it is working fine

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

    Good job

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

    Muito bom o conteúdo 👏👏👏👏👏

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

    Bro, Could you please upload automatically generate evosuite test suite in STs ?

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

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

    Please use free opensource ide like Eclipse or Spring Tool Suite for your videos thanks

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

    Where can I get that dependency

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

    I enjoyed the topic of the video, since unit tests are not necessarily what you have to do at school (and it's not in the curriculum).
    What I also liked was you switching to IntelliJ. I've been experimenting with my students, and we tested 3 different IDEs. They said that they felt most comfortable with IntelliJ and also appreciated the helpful tips that guided them towards fixing errors.
    I'd also like to give you props for the way you present the topics, among them being voice, intonation, gestures and pace.

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

      Truth to be told, curriculum for computer science in most university is outdated. Most lecturers stopped learning new things whereas the cs world is evolving every second.

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

      im taking a junit class rn and its a complete joke of a class.

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

      We actually have a course that goes all in on these features. It feels a bit awkward to do this much stuff for a conceptually small assignemt project but still something practically useful.

    • @gabrielv.4358
      @gabrielv.4358 ปีที่แล้ว

      so true. intellij is the better of them all, and its free

    • @impanthering
      @impanthering 2 วันที่ผ่านมา

      @@albertbokor6643 must be nice

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

    Thanks a lot !!!

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

    Thanks and kudos for the Coverage aspect in Intellij IDEA.

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

    Honestly there's no better refresher course on java unit testing than this. Short, precise, keeps your gears turning and leaves you wanting to know more.
    Thank you so much John.

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

    Very noice!!! As a “beginner” learning on my own these lectures are important lessons. Great Intro exposure to thinking about writing code holistically. Ty. 🙌🏿🙏🏾

    • @mohamedibrahim-qm1cr
      @mohamedibrahim-qm1cr 2 ปีที่แล้ว

      we should be friends lol i'm also just started Java! maybe CodingMates?

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

      @@mohamedibrahim-qm1cr where are you in your journey? Are you taking a course? With who? Asking for potential friend. Lol

    • @mohamedibrahim-qm1cr
      @mohamedibrahim-qm1cr 2 ปีที่แล้ว

      @@mastershonobi110 just in java for a week now, I'm in a bootcamp plus resource from Plural Sight.

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

      Yes, John's instructions are clear and to the point.

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

      @@mohamedibrahim-qm1cr Which level are you in? Did you reach objects and inheritance?

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

    Today, I crashed production because I didn't review and test my code. This was a valuable lesson for me. A colleague with more experience showed me how I could have detected this error through unit testing. We wrote 8 test cases within 20 minutes that could have assessed the functionality of my changes, and I would have noticed the bug. I am glad that we have an open culture for acknowledging errors, and that I was 'allowed' to make this mistake.

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

      I didn't realize how I had caused this error until we received emails from the company. In a mapper method, I used .filter(Objects::isNull) in a stream filter instead of .filter(Objects::nonNull). This led to the occurrence of the error on 6000 devices. It dawned on me that a slight oversight can impact hundreds to thousands of people. From now on, I will be more conscientious and refrain from putting my code into production until I am 100% sure that it performs its intended function.

    • @JoeyCodes
      @JoeyCodes 8 หลายเดือนก่อน +5

      How are ya'll getting jobs out here not knowing how to test your code ;-;

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

    I think this was a missed opportunity to change all those calculator tests to one simple parameterized test so that people who are learning how to write unit test do correctly from the start. Your tests were good and basic but wouldn't make it past default sonar unfortunately

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

      There was quite a bit of material that I could have kept going with, parameterized tests being one of them. (Mocking, TDD, mutation testing, @Before/@After types of annotations, etc.) The video is already quite long so I had to cut it off somewhere. Unit testing is one of my personal favorite subjects though, so at least some of those will probably be the subjects of future (hopefully smaller) videos.

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

      @@CodingWithJohn Yeah please cover all the topics your mentioned thanks for the amazing video.. appreciate your hardwork..

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

    Hell yea IntelliJ

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

    This is fine, but if you're writing more test code than actual code it seems wasteful. Also, what's testing the test code? Additionally, it's not always easy to just "create" an instance of the class under test, what if the class is abstract?. What if you're testing things that are unpredictable like network access clesses?

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

    TDD. Write the test 1st!

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

    How to test console app with MAIN function only ? With Scanner, input, output files ?
    Thank you in advance.

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

    Can you do a video about Heap sort and also Time complexities?? Thank you!!!

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

    It seems like after writing some code there will be hundred times more unit tests to be written

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

    These are all wonderful. I'm a retired Java 6 programmer writing
    Minecraft mods in Java 8, 16, and 17. Your videos are clear and concise! They help me a lot.

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

    15:00-16:00 wait how would 80 return a b ? When it is suppose to return a C when you set the condition to c< 81 so how would it be b?

  • @user-zj6iz1rl8d
    @user-zj6iz1rl8d 4 หลายเดือนก่อน +3

    i wish this dude made spring boot videoes would be gold

  • @muhammadhassaanbasil8599
    @muhammadhassaanbasil8599 9 หลายเดือนก่อน +5

    Concise, Crisp & To-the-point. Short videos, really time saving. Great work John.

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

    A video on lambdas expressions would be so awesome, especially when the concept is partnered with runnable class instances. These together are the only way I know in java to make a responsive GUI application.

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

    It was a good thing, thank you

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

    Why didn't you cover data providers for this topic? You've had great opportunity on both test classes to show people how instead of writing 100500 test cases you can write one method, which can cover all cases using data providers. And it would cost you just one additional minute, just to raise this topic, so new people could new how to write more efficient tests with less code.

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

    Your Code Editor looks similar to Android Studio. is it really android studio or something else ?

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

      It's IntelliJ. It looks similar because Android Studio is built on the IntelliJ platform.

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

    I've been trying to learn unit testing for ages and this made everything so much clearer!

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

    Isn't that a giant effort to just verify that something works? You could write that tests simply in the main method or run and debug your way into the error location. I don't see any advantage of a bloated clunky testing framework.

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

      You could, but it is always nice to know the "standard way" to do this, in case you are in a company and they require it. If you are doing your own personal projects, do whatever you want, but in a company where you have different programmers, keeping up standards is important.

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

      @@theblindprogrammer fair enough

  • @oleksiil.9892
    @oleksiil.9892 2 ปีที่แล้ว +1

    Very cool stuff for a java beginner like myself )) thank you!

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

    Another great video John!
    Looking forward to the jvm memory management video; if possible please give it a shot ...

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

    The classes I want to do my unit test on, should they be in their own separate .java source code file? What if the custom class I want to test is written in a java source code file that also contains the main method, where should my unit test be written in that scenario? Great video!

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

      You should still write your UTs in another java file. If all your code is in one single class, "unit tests" are a bit tougher to do, since the entire point of unit tests are testing single classes with one purpose to make sure it does what it should, and not for testing a program as a whole. So you might break out meaningful classes and test the functionality of those classes with unit tests.

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

      @@CodingWithJohn Thanks!

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

    You're brilliant! I'm a senior Java developer but I don't have these didactics and ease to explain/teach. Awesome job

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

    John, i almost said that this was the most easy topic i learned in java, but when i read other comments, i realized its because your teaching method is simply great. I’m glad i found you!

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

    Hey, first of all, a huge thank you for making these videos! they're great help to me and anyone that is studying and learning java on their own or even in school but need more to understand everything better.
    Also, I wanted to ask if you have any plans about making a video of how to use an API. I do know it's very simple to look it up in the internet, but your videos are very clear and easy to understand so it would definitely help me a ton! thanks in advance:)

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

      I am just curious, what kind of an API are you looking for? Are you looking for TH-cam API or Twitter API? If so, let me know I might attempt it showing you how, I am not as good as John (obviously), but I can try.

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

      @@theblindprogrammer I was looking for a more general view of it and overall how it works, I have an idea of the process as I studied it in python a year ago in university and even though I can't remember it very well now, if it's anything like python, it should be pretty simple to get into. I practice java by doing small to medium projects and every time I try to implement something new that I've studied into my project, and I'm feeling API's would be a nice addition!

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

      @@lqrock5438 Yeah, calling APIs in Java is similar to python except in Java, it is a lot more verbose than needed. You can try it with news APIs.

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

    Looking for a video that will show a full example of a REAL WORLD class that needs to be UNIT TESTED.
    UseCase with injected repositories lets say and Explain when Mock? When Fake? What to test in REAL WORLD apps.
    Good video to talk wth your friends, but now value to real development.

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

    Hey John, I was wondering why you switched to IntelliJ from Eclipse. In university we used Eclipse but I have used IntelliJ a few times too. Many people have told me that I need to switch because IntelliJ is said to be so much better, but I am scared of relearning all hotkeys and functions of the IDE. What do you think?

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

    I am getting this error every time when I run the single tests in IntelliJ
    java: cannot find symbol
    symbol: class someClassName
    location: class com.source.aaa.bbb.directory.entities.modelname
    Can you help with this please.

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

    Thank you so much bro, could you make a video about integration tests? And the use of @Mock and @InjectMocks annotations? It would ve awesome, thank you! God bless you my friend! :)

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

    Thanks for your video. I almost see all your videos. So Could you make more videos like the tools, Maven, or Git, or deploy projects into AWS. Thank you so much.

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

    You get an 'E' for this video just like the grade you skipped in the determineLetterGrade method :D I'm just joking of course, excellent video as always

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

    Hi John, thks for your videos, there are great. The only issue I see here is that you are using on this video another IDE. Why ? Most of your videos are using Eclipse as IDE, and that is the IDE I am using too. I tryed to to apply the concepts of the video above on my Eclipse environment, and I am getting lost with the maven issue, and with the wizards. Will be possible to have a version of this video based on Eclipse, so the people is using your course is able to better follow this topic ?

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

    Is there something similar to Run With Coverage that you caan do in VS Code? Especially, for C/C++?

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

    JUnit5 🤘. Still waiting on Android tests supporting this officially, will probably never happen though

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

    Nice video, but a claim like 'you may be abolutely sure, that your code is correct" is too far streched. In some cases, you might be able to do exhaustive tests and are absolutely sure, but in most cases you can't.
    Improving the probabilty to catch an error, especially writing tests to catch errors, which have occured once, is still a very valuable help.

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

    Hey, I'm getting ExceptionInInitializer error while running cases but not able to find the way. could you help me with the tips ? what to do

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

    Thank you for your video. Could you please tell in which directory is the Junit XML file generated ? Thanks a lot!

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

    Please do JVM, JDK, JRE. I have been coding since 2 years yet struggle to understand it. Please help.