1 00:00:00,025 --> 00:00:04,372 [SOUND] Hello, I'm Craig, 2 00:00:04,372 --> 00:00:07,964 and I'm a developer. 3 00:00:07,964 --> 00:00:10,350 This course does come with a few prerequisites, so 4 00:00:10,350 --> 00:00:13,330 please make sure that you are all caught up with those. 5 00:00:13,330 --> 00:00:17,370 I am going to assume that you, as a Java developer, know what I'm talking about. 6 00:00:19,360 --> 00:00:21,980 Remember that there are speed controls on the video player, and 7 00:00:21,980 --> 00:00:27,870 you can always speed up or make me go really slow, and I won't mind at all. 8 00:00:27,870 --> 00:00:30,670 Also, keep in mind that there are usually pretty 9 00:00:30,670 --> 00:00:33,440 detailed notes attached to each video. 10 00:00:33,440 --> 00:00:36,220 I usually will point them out, but don't forget to check them out for 11 00:00:36,220 --> 00:00:37,120 more juicy knowledge. 12 00:00:38,430 --> 00:00:42,970 In this course, we are going to explore the wonderful world of automated testing, 13 00:00:42,970 --> 00:00:45,710 more specifically, unit testing. 14 00:00:45,710 --> 00:00:48,960 Together, we'll explore the terminology, concepts, 15 00:00:48,960 --> 00:00:51,110 and many of testing's best practices. 16 00:00:52,210 --> 00:00:55,710 We'll talk about why, how, and what to test. 17 00:00:57,320 --> 00:00:58,570 Well, wait a second. 18 00:00:58,570 --> 00:01:00,680 What about when, you ask. 19 00:01:00,680 --> 00:01:02,100 Well, we can cover that right now. 20 00:01:03,440 --> 00:01:07,659 The answer to when should we test is this, always. 21 00:01:07,659 --> 00:01:10,517 You should always test. 22 00:01:10,517 --> 00:01:14,620 But, but, but, but we haven't been testing in previous courses. 23 00:01:14,620 --> 00:01:15,910 I know, right. 24 00:01:15,910 --> 00:01:17,080 It was killing me. 25 00:01:17,080 --> 00:01:19,070 By the time we reach the end of this course, 26 00:01:19,070 --> 00:01:21,820 I hope you'll be in complete agreement with me. 27 00:01:21,820 --> 00:01:26,360 Testing is a lot of fun, and I know you're gonna have fun with this course. 28 00:01:26,360 --> 00:01:31,270 Testing your code properly ends up driving a lot of good programming habits home. 29 00:01:31,270 --> 00:01:34,900 Now, throughout this course, I'm gonna through in a few new object 30 00:01:34,900 --> 00:01:39,600 oriented techniques that will help your code not only be more extensible, but 31 00:01:39,600 --> 00:01:41,150 also more testable. 32 00:01:42,680 --> 00:01:47,480 We'll be using Intelli-J idea to exercise the J unit testing framework. 33 00:01:47,480 --> 00:01:49,830 If you don't have Intelli-J installed on your machine, 34 00:01:49,830 --> 00:01:53,260 make sure to check the prerequisites for the local development environments course. 35 00:01:54,600 --> 00:01:55,360 There are for sure 36 00:01:55,360 --> 00:01:57,910 other testing frameworks that you might end up working with. 37 00:01:57,910 --> 00:02:01,110 And every language has its own flavor of testing. 38 00:02:01,110 --> 00:02:03,960 Just about every one of the concepts that you'll learn in this course 39 00:02:03,960 --> 00:02:07,210 will be transferable, not only to those other frameworks, but 40 00:02:07,210 --> 00:02:08,330 also to the other languages. 41 00:02:09,910 --> 00:02:13,220 There's an inevitable time in every project, and 42 00:02:13,220 --> 00:02:15,460 it's usually right before the product launches, 43 00:02:15,460 --> 00:02:19,190 where the dreadful question of are we sure this works is asked. 44 00:02:19,190 --> 00:02:25,620 Let's take a quick look at how this is answered before testing is in place. 45 00:02:25,620 --> 00:02:28,300 So the client asks, so we're launching this tomorrow? 46 00:02:28,300 --> 00:02:30,100 Are you sure that it works? 47 00:02:30,100 --> 00:02:35,930 And you and your team are like, yeah, totally, sure. 48 00:02:35,930 --> 00:02:38,770 And the client goes hm, just making sure you all 49 00:02:38,770 --> 00:02:42,280 thought about what happens when the user didn't provide their last name, right? 50 00:02:43,530 --> 00:02:48,326 And then the team looks at each other and goes, yeah, totally, uh-huh, 51 00:02:48,326 --> 00:02:52,370 uh-huh, yeah, yeah, yeah, and then when the meeting's over, 52 00:02:52,370 --> 00:02:56,070 everyone rushes back to their computers to see what actually happens. 53 00:02:56,070 --> 00:02:58,970 And they do this by adding console print statements and 54 00:02:58,970 --> 00:03:01,960 actually booting up a new profile without a last name, 55 00:03:01,960 --> 00:03:06,150 and then they try to look at all the pages where the user is displayed. 56 00:03:06,150 --> 00:03:09,110 It turns out the code isn't shared across each page. 57 00:03:09,110 --> 00:03:11,460 So they decide to split up and tackle each page. 58 00:03:12,872 --> 00:03:15,470 Now thankfully, several errors are found, 59 00:03:15,470 --> 00:03:18,670 and everyone starts rushing and submitting their code to the shared code base. 60 00:03:18,670 --> 00:03:23,427 They all feel good and safe and they high five [SOUND] but then someone says, 61 00:03:23,427 --> 00:03:28,195 hey, that last change you made ended up breaking this other widget. 62 00:03:28,195 --> 00:03:31,346 So they start fixing that widget and then they break another thing and 63 00:03:31,346 --> 00:03:33,610 then that fix breaks another thing. 64 00:03:33,610 --> 00:03:36,540 Then they end up pushing back launch a couple of weeks. 65 00:03:36,540 --> 00:03:40,550 But after working lots and lots of long nights, it all finally goes live. 66 00:03:41,650 --> 00:03:42,150 Phew! 67 00:03:43,170 --> 00:03:44,066 Now are you ready for 68 00:03:44,066 --> 00:03:47,870 the real sad part of the story of the team without testing in place? 69 00:03:47,870 --> 00:03:50,400 The errors start piling in from their users, and 70 00:03:50,400 --> 00:03:54,690 as the pattern of fix one thing break two more continues, soon they're spending 71 00:03:54,690 --> 00:03:57,890 most of their time fixing bugs instead of making new features. 72 00:04:00,040 --> 00:04:04,178 Now let's take a look at a different world, one where testing is in place. 73 00:04:04,178 --> 00:04:09,430 It's the same story, it's the day before launch, and the client asks, 74 00:04:09,430 --> 00:04:12,810 so we're launching this tomorrow, are you sure this works? 75 00:04:12,810 --> 00:04:14,440 And you and your team are like, yep. 76 00:04:15,970 --> 00:04:18,720 And the client goes, just making sure you all 77 00:04:18,720 --> 00:04:23,000 thought about what happens when the user didn't provide their last name, right? 78 00:04:23,000 --> 00:04:26,557 And you respond with, yeah, I'm pretty sure, let me check the test real quick. 79 00:04:26,557 --> 00:04:29,070 And you open up the User Profile Tests. 80 00:04:29,070 --> 00:04:30,644 You look at the test name and 81 00:04:30,644 --> 00:04:35,304 immediately see one that says displayingUserWithFirstNameOnlyShowsFirst. 82 00:04:35,304 --> 00:04:37,476 And you tell them that the test their passing and 83 00:04:37,476 --> 00:04:40,037 that anytime we show their name, we use this approach. 84 00:04:40,037 --> 00:04:42,557 And everyone high fives at the successful launch. 85 00:04:42,557 --> 00:04:45,373 And then when bugs come in, they're fixed, and 86 00:04:45,373 --> 00:04:49,230 a test is written to make sure that that error never happens again. 87 00:04:49,230 --> 00:04:53,887 And all the tests prove that the change didn't break anything else. 88 00:04:53,887 --> 00:04:56,330 See what a different world you can create? 89 00:04:56,330 --> 00:05:00,320 Now I realize that this was just a fictionalized reenactment, but 90 00:05:00,320 --> 00:05:01,670 that's the idea. 91 00:05:01,670 --> 00:05:04,340 How much better must that confidence feel? 92 00:05:04,340 --> 00:05:06,930 Don't you want what's behind door number two? 93 00:05:06,930 --> 00:05:08,520 I want it for you, too! 94 00:05:08,520 --> 00:05:09,960 Well then, let's get started.