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

Full tutorial on creating Unit Tests in Java with JUnit!
Do you write Java code that you're just not confident is 100% right? You can create unit tests using the JUnit testing framework to verify your Java code, and I'll show you exactly how to do it.
Many beginners don't know there's a great way to test their code with simple, fast tests and make sure their code is working exactly how they think it is.
The IntelliJ testing tools also make creating and running your Unit Tests super simple.
In this beginner's Java tutorial video, we'll do a full walkthrough of why and how you can create your own unit tests!
Learn or improve your Java by watching it being coded live!
Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
Let me know what else you'd like to see!
Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
📕 THE best book to learn Java, Effective Java by Joshua Bloch
amzn.to/36AfdUu
📕 One of my favorite programming books, Clean Code by Robert Martin
amzn.to/3GTPVhf
🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
www.audibletrial.com/johnclean...
🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
bit.ly/3QPNGko
📹Phone I use for recording:
amzn.to/3HepYJu
🎙️Microphone I use (classy, I know):
amzn.to/3AYGdbz
Donate with PayPal (Thank you so much!)
www.paypal.com/donate/?hosted...
☕Complete Java course:
codingwithjohn.thinkific.com/...
codingwithjohn.com

Пікірлер: 442

  • @Roberto-oz6et
    @Roberto-oz6et2 жыл бұрын

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

  • @jeromepincus8529

    @jeromepincus8529

    8 ай бұрын

    So true

  • @marmont8005
    @marmont80059 ай бұрын

    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

    9 ай бұрын

    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

    5 ай бұрын

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

  • @tejumania
    @tejumania Жыл бұрын

    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.

  • @muhammadhassaanbasil8599
    @muhammadhassaanbasil85995 ай бұрын

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

  • @raghavanaliassaravananm1546
    @raghavanaliassaravananm15462 жыл бұрын

    Thanks and kudos for the Coverage aspect in Intellij IDEA.

  • @gplus46
    @gplus462 жыл бұрын

    "run our test with coverage" was a requirement for project...Its clearer now. That was a treat. Great video

  • @macmcleod1188
    @macmcleod1188 Жыл бұрын

    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.

  • @samueldnc
    @samueldnc2 жыл бұрын

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

  • @olillin
    @olillin2 жыл бұрын

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

  • @xq510
    @xq5102 жыл бұрын

    THIS IS AMAZING! I loved how you provided context and explained everything so clearly!!

  • @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.

  • @Hurosaki_
    @Hurosaki_Ай бұрын

    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!

  • @DC-sp4sk
    @DC-sp4sk2 жыл бұрын

    Best video ever on JUnit by a long shot. Would really love to see more advanced videos on this topic!

  • @amjadsaad9545
    @amjadsaad95458 ай бұрын

    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❤

  • @samueloverspelham2322
    @samueloverspelham23222 жыл бұрын

    As a Java developer, this channel has been very helpful to me in every way.. Thanks to you.

  • @Chronozia
    @Chronozia2 жыл бұрын

    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!

  • @diegoruiz5265
    @diegoruiz52652 жыл бұрын

    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 !

  • @gabrieldenobrega
    @gabrieldenobrega Жыл бұрын

    Thank you for this video. It's clear that this video is just a summary of what unit tests are just like you said. However, only your video was able to really make me understand what unit testing in Java is about.

  • @nipunlakshank
    @nipunlakshank Жыл бұрын

    This is the best beginner friendly unit testing tutorial I've found so far

  • @paulus_germanus
    @paulus_germanus27 күн бұрын

    Hands down the best Java channel on YT. I love you John. You just very clearly explained to my dumb brain what the rest of the web really struggled to achieve. Thank you!

  • @JLSXMK8
    @JLSXMK82 жыл бұрын

    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.

  • @micleh
    @micleh2 жыл бұрын

    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

    Жыл бұрын

    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

    Жыл бұрын

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

  • @albertbokor6643

    @albertbokor6643

    Жыл бұрын

    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

    9 ай бұрын

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

  • @lekhanh9085
    @lekhanh9085 Жыл бұрын

    Thanks John, I understood the basics of JUnit test in Java through your easy to understand examples. 😊

  • @eduonnetcomputer8878
    @eduonnetcomputer887811 ай бұрын

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

  • @mrnoname2462
    @mrnoname24624 ай бұрын

    Been exposed to introduction of JUnit today, lucky to have this lesson!

  • @alexanderanastasiadis9284
    @alexanderanastasiadis92842 жыл бұрын

    Hi John , you are the reason who i love the Java. Every video is incredible understandable. Thanks a lot 😎

  • @Roshni1406
    @Roshni140610 ай бұрын

    Hey John Thank you so much for this video , you were just explain the basic unit testing in a simple way. This is a great video for beginners.👍

  • @TomAinsworth94
    @TomAinsworth94 Жыл бұрын

    Awesome vid John, thanks for going into so much detail in an actual use case!

  • @ndk8111
    @ndk81112 жыл бұрын

    Thanks John. Finished your lecture then went to try to implement a few of the junit5 test methods for the very first time. Your explanation was very good. One thing I wished you touched was how to resolve dependencies needed to run junit5. I grabbed one of the dependencies in mvn repository Jupiter-engine and that seemed sufficed to resolve my missing assertTrue(). These small things very briefly but ought to be covered In your demos I think.

  • @ajithak.s.5224
    @ajithak.s.52242 жыл бұрын

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

  • @juancarloscardona5613
    @juancarloscardona56132 жыл бұрын

    Thanks for this video! I recently joined my first hackathon and I was looking forward to using unit testing in Java for the first time, you explained it very well and it was easy to understand. Nice work :)

  • @carloschacon5951

    @carloschacon5951

    2 жыл бұрын

    MinTIC???

  • @mahodaadikari4116
    @mahodaadikari41162 жыл бұрын

    Thanks John. Another crystal clear explanation. Straight to the point 👌 💯

  • @tarifadib
    @tarifadibАй бұрын

    thank you, i was able to create and test individual test cases with this video.

  • @waffle8364
    @waffle83648 ай бұрын

    The one testing framework I've ever loved and enjoyed was RSpec for Ruby or Rails. Extremely easy to setup, read and write tests.

  • @darsanas6741
    @darsanas674111 ай бұрын

    Thanks a lot John. I started loving Java after watching your videos! This topic was so interesting.

  • @gabrielv.4358
    @gabrielv.43589 ай бұрын

    That is insanely complicated, wow! So cool!

  • @milenatenorio2506
    @milenatenorio25068 ай бұрын

    Thank you very much for the video! The teaching and English are perfect for people who do not speak English as a native language.

  • @illegalgiant_
    @illegalgiant_ Жыл бұрын

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

  • @brenodelgado1128
    @brenodelgado11282 жыл бұрын

    Hey John, congrats for your content. It's really clarefull and understood. Thanks from Brazil, let's keep coding.

  • @Decent138
    @Decent13810 ай бұрын

    i have not understands this topic in my class but now i am perfect with this topic.... Thank you professor

  • @lucasalledi
    @lucasalledi Жыл бұрын

    going through your classes while taking part in a bootcamp. really appreciate your help!

  • @CodingWithJohn

    @CodingWithJohn

    Жыл бұрын

    Glad it's helping!

  • @semilife
    @semilife5 ай бұрын

    John your videos are great, clear concise and informative.

  • @K4ziq
    @K4ziq2 жыл бұрын

    Hey John! Thanks for your hard work! You do great job with this short explanatory videos! Create one with lambda expression please! :)

  • @slai2389
    @slai23898 ай бұрын

    Thanks for your video sincerely. Every time I learn new things from you.

  • @umiskan5819
    @umiskan58199 ай бұрын

    Great explanation! Great work! Simple and to the point Thank you!

  • @Wow-uj3uj
    @Wow-uj3uj4 ай бұрын

    This video has made me subscribe. So well spoken and well communicated I had no choice! Thank you for this very informative video

  • @yogeshdharya3857
    @yogeshdharya385710 ай бұрын

    Had an assignmen to perform unit testing in Java usign the Junit . Was recommended to watch this video of yours . Your doing a great job ceating content for beginners like me Sir John . Had to subscribe ! Keep up the good and humble work !😇

  • @CodingWithJohn

    @CodingWithJohn

    10 ай бұрын

    Awesome, I'm glad it helped! And thankful to whomever recommended it!

  • @mastershonobi110
    @mastershonobi1102 жыл бұрын

    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 жыл бұрын

    @@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 жыл бұрын

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

  • @theblindprogrammer

    @theblindprogrammer

    2 жыл бұрын

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

  • @lonesareer
    @lonesareer2 жыл бұрын

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

  • @dipalisavaliya295
    @dipalisavaliya295 Жыл бұрын

    very nicely explained in short time and covered very good scenarios!! Thanks for your efforts :)

  • @iamhassell
    @iamhassell2 жыл бұрын

    Great intro to unit testing John, awesome! Thanks!

  • @oleksiil.9892
    @oleksiil.98922 жыл бұрын

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

  • @my_video_collection
    @my_video_collection9 ай бұрын

    now 2:23 am, but I'm sitting and watching you. It's so cool. Firstly I'm learning Java, secondly I'm improving my English (at least listening)😍

  • @whitneythung2792
    @whitneythung2792 Жыл бұрын

    This is an awesome tutorial on how to write JUnit Tests. You explained this so well for a slow learner like me. Thanks for the help!

  • @CodingWithJohn

    @CodingWithJohn

    Жыл бұрын

    Glad it was helpful!

  • @sirfranciscanadianbacon1468
    @sirfranciscanadianbacon14682 жыл бұрын

    That was so well described. Very very helpful. Your videos are also produced very well.

  • @sunruiheng4255
    @sunruiheng425510 ай бұрын

    Awesome overview and introduction to JUnit, thanks!

  • @henryicruise860
    @henryicruise8602 жыл бұрын

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

  • @matiasmoresi5040
    @matiasmoresi5040 Жыл бұрын

    Beautifully explained! Thank you very much!

  • @mohamed-alimessedi3
    @mohamed-alimessedi3 Жыл бұрын

    Thank you very much for sharing this in such a clear way.

  • @anjananisal2672
    @anjananisal2672 Жыл бұрын

    Crystal clear explanation, thank you!!

  • @prashanthdp9501
    @prashanthdp9501 Жыл бұрын

    Very organised and very well explained, Thank you!

  • @vinaypawde9894
    @vinaypawde98942 жыл бұрын

    Hi John.love your videos..you explain both concepts and code very clearly..could you please do a video around stack/queues and bfs/dfs algos? Thanks a lot :)

  • @animeshsrivastavash
    @animeshsrivastavash2 жыл бұрын

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

  • @regatonic
    @regatonic Жыл бұрын

    That was excellent, love your tutorials!

  • @beetc305shivsundarbankar9
    @beetc305shivsundarbankar9 Жыл бұрын

    Hit the like, if you have been watching many tutorials and finally, you get the proper context with clear explanations.

  • @k.k9206
    @k.k92062 жыл бұрын

    That was awesome john! great explanation! Thank you so much.

  • @rrroman870
    @rrroman8702 жыл бұрын

    Thanks so much for the tutorial. It helps a lot!

  • @vivzyw
    @vivzyw2 жыл бұрын

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

  • @ribamiltombezerradelima3483
    @ribamiltombezerradelima348310 ай бұрын

    Wow! Thank you so much! Your video is really helpful and engaging! Keep it up,pal!

  • @harshachakraborty3505
    @harshachakraborty35052 жыл бұрын

    Hi John, Thanks for all these videos. Please make a video on concepts of functional interface and lambda expression.

  • @michael_scarn_
    @michael_scarn_10 ай бұрын

    Thank you John, much appreciated!❤

  • @ultimateguru2
    @ultimateguru22 ай бұрын

    Every time i look up something on youtube regarding java, and I see johns video available on that topic, what a sigh of relief, hushhhh.! 😅

  • @CodingWithJohn

    @CodingWithJohn

    2 ай бұрын

    Let me know if there's something crucial I haven't covered yet!

  • @PappyTrading
    @PappyTrading2 жыл бұрын

    Thanks for making current and superior Java videos

  • @jp77355
    @jp77355 Жыл бұрын

    TY!, the exception part was the best in the video!

  • @seanwagner3917
    @seanwagner3917 Жыл бұрын

    Easy to follow, comprehensive from my beginner's point of view, and to the point. Do you recommend someone else's deeper dive into unit testing specifically, or say (integration) testing more generally? Thank you. Oh yes: subscribed.

  • @tarikuasfaw6405
    @tarikuasfaw64052 жыл бұрын

    Wow I pretty much appreciate you John I am so happy to get your channel

  • @jhonysantosdesouza
    @jhonysantosdesouza8 ай бұрын

    It's a wonderful video!! Many thanks John

  • @nyizeya99
    @nyizeya992 жыл бұрын

    Your contents are really helping

  • @samuvisser
    @samuvisser2 жыл бұрын

    Long time programmer but never wrote a single unit test. Its this thing i know i should do, but I seriously never have time for. This video is a actually a great example, ur unit tests tend to use as much or even more lines of code than the original. In the real word the next deadline is always yesterday…

  • @SuperShogee
    @SuperShogee2 жыл бұрын

    Hi John, thanks for making these awesome java tutorial videos. I've been looking into invariants in java and no one knows how to simply explain concepts like you do. They all have these long drawn out explanations that don't make any sense to anyone without years of java experience. Can you please make a video on invariants? Thank you in advance.

  • @DavidVCastro
    @DavidVCastro4 ай бұрын

    Amazing how much you covered in 21 minutes!

  • @igorkulishov8285
    @igorkulishov8285 Жыл бұрын

    Awesome! Thank you so much! Great explanation.

  • @melbali7828
    @melbali7828 Жыл бұрын

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

  • @adrianprayoga335
    @adrianprayoga335 Жыл бұрын

    underrated java youtuber, man deserve more views, thanks for the tutorial

  • @gasynormand8371
    @gasynormand83712 жыл бұрын

    I actually liked the video even i did not started to watch it yet. I wanted this video to come so much. Thank you

  • @CodingWithJohn

    @CodingWithJohn

    2 жыл бұрын

    Hope it lives up to your expectations!

  • @Johnny-tz2dx
    @Johnny-tz2dx2 жыл бұрын

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

  • @soumikbanerjee3059
    @soumikbanerjee30592 жыл бұрын

    Thanks. Got a clear understanding.

  • @dougeighteenfifty980
    @dougeighteenfifty9802 жыл бұрын

    Nice intro to unit tests! An intermediate one about Mockito would be an excellent progression.

  • @peanuthead32
    @peanuthead327 ай бұрын

    this was just amazing. very well explained.

  • @FukSN
    @FukSN2 жыл бұрын

    Nice tutorial and well explained as usual. Thank you

  • @joaopaulocorreaparise5126
    @joaopaulocorreaparise51262 жыл бұрын

    Love your content! Keep on, John!

  • @user-pb6ps2mb4y
    @user-pb6ps2mb4y2 жыл бұрын

    John! Thanks a lot!!!! Your video was super duper helpful! Really simple and clear for a novice!!! Like and subscription!

  • @rollingdice
    @rollingdice2 жыл бұрын

    thanks John, I learned some new info from this lesson

  • @simonandris4730
    @simonandris47306 ай бұрын

    That was very informative . Thanks for sharing your knowledge with us

  • @natashasthilaire1950
    @natashasthilaire1950 Жыл бұрын

    This video was amazing, thank you!!!

  • @mani8586
    @mani85862 жыл бұрын

    Hi John, great stuff can you have some videos over dynamic programming and design patterns as it would be helpful.

  • @user-ie9yw4wr2j
    @user-ie9yw4wr2j2 ай бұрын

    Thanks!!! Eezy tutorial on unit testing

  • @2002egncn
    @2002egncn Жыл бұрын

    Very well explained! Thank you.

  • @lauraluo7242
    @lauraluo72423 ай бұрын

    U are amazing bro. For one video, I understand Unit testing.

  • @caranthirn7400
    @caranthirn74002 жыл бұрын

    Thank you for this great tutorial.

Келесі