 You're here because you're asking the question, what is unit testing? Maybe you need it for study, maybe you need it for a new job. Whatever the reason, we're gonna build understanding together through an analogy, and then we'll go off and define it. Hang around to the end of the video as well as I'll share with you why they're critical to becoming an awesome developer. So let's dive into the screen in just a sec. Hello world, I'm the surfing scratcher, teacher-surfing programmer, and on this channel I help curious learners just like you along on your learning journey. So this video is all about unit testing and we're gonna answer the question, what it is? In order to help your understanding, I want you to think about this blue rectangle here. This blue rectangle represents maybe a game you've created, it might be a world, and in that world you define your own rules for things to happen. Now outside of this rectangle, there are external things, things that wanna come into your world, things that wanna interact with your world. These things could be numbers, they could be some text, and they could be some dangerous things as well that we don't really want to come into your world. So you can think of unit testing as a bit of a gatekeeper. It's sort of like you're allowing the things that you want to come into your world and you're blocking the things that you don't really want into the world. Let's go ahead and define it. So it's basically isolating a little piece of code to check to see it works as expected. So we're kind of breaking down a huge application into some small parts. Okay, so if it's just a piece of code that we check to see it works as expected, then what exactly should we check? Let's just jump across to some code to have a quick look at it right now. On the screen right now, I've got an activity from the brilliant website Exorcism.org where you can go to learn virtually any programming language, it's really awesome. What they do to ensure you're ready to move on is they send all the functions that you write through unit tests. So here on the screen, this is called high scores and there's just three functions here, the latest score from a list of scores, the personal best and getting the personal top three. So I've gone ahead and implemented all of these three functions. But how do we know that they're implemented correctly? Well, that's where we put them through some unit tests. So I'll just bring that up on the screen now. Okay, I've got that unit test file up right now and it might look a little bit intimidating and the details don't matter right now. I just wanted to show you what it looks like. So here you can see that there are a whole heap of Python functions here and they're kind of categorized into tests. We've got test latest score and we just wanna check that the latest score here, so 30 has been appended to this list. We wanna see if that answer is actually 30. So we wanna test the latest scores. They're testing my function here, latest scores, that the latest one is actually 30. So it just sort of runs. It passes in this list to my function latest and making sure that 30 is the result. So thinking back to our rectangle analogy, my rectangle is this function here, latest scores and we're passing in those values. Here we're passing in a number value. If my function didn't return 30, then it would not pass the test and Exorcism would know about that. Okay, so that's just a real brief taster into what unit tests look like. Let's return to that question. What exactly should we be checking? Well, the list is kind of endless, but a good starting point is really just to check that the data type that you're expecting. So in that example before, we're making sure that we're getting some numbers. We can maybe check some regular expressions. Maybe you're working on a regular expression and you are trying to figure out the right pattern for it and you wanna pass in some strings to make sure that your pattern is doing what it's expected to do. Or maybe you wanna check that a value is within an expected range, a little bit similar to what you just saw on the screen in the Exorcism example. And really, that's all a unit test is. It's an isolated bit of code that we check to see is doing what it's supposed to do. Of course, there is loads more under the hood of unit tests, such as asking the question, why is unit testing important? And that's something I'm gonna get to in another video. And if you're interested in that, go check the card on the screen right now. But until next time, I'm off to go find a way. I'll see you in the next one.