 Come on, really? Why is unit testing important? That's the question you're asking, isn't it? And honestly, you're right to question it. It seems like such a big waste of time. But in this video, I'm going to share with you why it's critical to adopt unit testing if you're serious to become a respected developer. Hang around till the end as well, and I'll show you how to get started with writing unit tests on replete. So let's dive into the screen in just a sec. Hello world, I'm the surfing scratcher, teacher, surfer, programmer, and on this channel, I help curious learners just like you along on your learning journeys. You're here because you've got a question rumbling around in your head. Why is unit testing important? So I'm guessing that you already know what a unit test is. It's just a little bit of code that we check to see if it does what it says it's going to do, right? But like, why go to all this trouble to do that in the first place? Well, to sort of set the scene in the context for it, I've got a little video that I'd like to share with you from a documentary called The Machine that changed the world, and that machine is the computer. So I've got about a minute that I want to share with you, and then we're going to go over a few tips of why unit testing is important. The clip starts off with a software developer from the 60s talking about the experience of writing software for early computers and the complexities surrounding that, and then it transitions into talking about the systems of an aeroplane before finishing with another software developer who talks about how complicated it was back then to write software for early computers. In the modern age, thanks to unit testing, finding errors in our code is a lot more like finding errors in the aeroplane in this clip. So let's go check out this super retro clip. I believe that that that these things are like the product I'm working on now is far more complex than a 747 is. A few miles away at the Boeing factory, engineers turn out hundreds of planes each year. A 747 has six million parts which have to be put together correctly, but at least when something goes wrong you have a good chance of finding it. With physical things like airplanes and buildings, if there is a fault you look to see if the problem is nearby. So if you've got something that's not holding its weight well, you look to see if the joint is tight, if the screws are right, if they're... you don't have to go and analyze the whole building. Well, software doesn't work like that. If you see a problem when you attempt to execute a certain command, there is no simple and direct way of knowing which part of the code could have the problem. In some sense it could be almost anywhere. And so the detective problem of hunting down the source of the problem is enormously harder than in physical media because digital media don't obey the same simplifying law of proximity of cause and effect. So based on that clip, I hope it's become immediately clear that unit tests help break down an application. Think of your application just like that big airplane. It breaks it down into all these little parts where we can detect the flaws. You can detect them early in the code which could be hard to find down the track. When you develop your applications using unit tests, you're finding problems earlier on. You're not finding them down the track. Not to say that there won't be problems down the track, but you're able to fix them when they're early on. They're less costly. You're less progressed with your development. And just like we saw with the airplane, it's easier to debug because you've basically created your application that is based on all these tests and it's telling you where exactly your logic is breaking down. And that leads into something called continuous integration where you can have this sort of automated in the background when you're working as part of a large team and you've got a new developer who comes on and changes something in the code. And if they change something existing to something that it shouldn't be, then we can check this automatically and identify the problem straight away. We're not left scratching our heads to wonder why or where this problem occurred. And this is probably less interesting for you, but it's a great way to create some documentation. So if you're working on an application and someone else needs to come in and look at it, those developers, those other people can come in and look at your tests for examples of how it should work. Because sometimes it can be a little bit ambiguous to understand what the application is doing. Okay, so these were just a few points telling you why unit testing is important, but that's not the full story. There are some drawbacks. What are they? Well, the first drawback is time. It takes a little bit more time up front to be making these tests. It's sort of getting in the way of your development. But I'd argue that if your code is really messy, then there's going to be a greater time cost down the track. It's one of those examples where if you delay the gratification or you put in the hard work up front, there's a payoff down the track. Whereas if you take the shortcut initially, sure, it's less painful then, but because you've been kind of sloppy with it potentially, that the time is going to increase down the track and that is going to increase your pain. Straight up. Unit tests can be intimidating. If you've never done it before, where do you start? There is a huge learning curve with it, especially if you're an individual developer. You might be asking yourself, why on earth would I bother doing this for myself? Well, it's certainly going to make you and your code more robust and more attractive. And it can be a real pain in the butt to work with external data, because then you've got to basically simulate or make up what that data would be. So then you could run your test with it. So there's almost an extra layer that you need to go to, but I wouldn't necessarily see this as a drawback because you probably want to go in and mock up this data anyway while you're writing your application. So it's a really good way to just decouple your code and test it in isolation, which is exactly what unit testing does. Okay. So this video has hopefully offered you some answers to the question, why unit testing is important? We've gone over a few reasons why you would use unit testing and a few of the barriers to entry. Now that you know what unit testing is and why it's important, I think you're about ready to jump into a demo. So we'll do that in another video. I'm sure there'll be a card coming up on your screen right now. So until next time, I'm off to go find a wave and I'll catch you in that demo video. See you there.