1 00:00:00,000 --> 00:00:04,774 [MUSIC] 2 00:00:04,774 --> 00:00:06,937 Spend any time learning about programming, and 3 00:00:06,937 --> 00:00:11,560 you're gonna come across the acronym TDD, which stands for Test Driven Development. 4 00:00:11,560 --> 00:00:14,910 In TDD, once you know what you're going to build, you write the test for 5 00:00:14,910 --> 00:00:17,010 it before you write the code. 6 00:00:17,010 --> 00:00:18,440 For some people, this works. 7 00:00:18,440 --> 00:00:20,020 For others, it doesn't. 8 00:00:20,020 --> 00:00:22,940 Don't feel bad if TDD doesn't make sense to you right now. 9 00:00:22,940 --> 00:00:26,440 What's important is that you write tests, not whether you write the test before you 10 00:00:26,440 --> 00:00:30,410 write the code, or whether you write tests for code that you've already written. 11 00:00:30,410 --> 00:00:31,970 So what is a test? 12 00:00:31,970 --> 00:00:35,080 In this course, when I talk about tests, I'm really talking about unit tests. 13 00:00:35,080 --> 00:00:37,850 Well that brings up another question, huh? 14 00:00:37,850 --> 00:00:39,520 What the heck is a unit? 15 00:00:39,520 --> 00:00:42,240 A unit is a single feature or aspect of your code. 16 00:00:43,260 --> 00:00:44,920 Say you have a class that represents a car. 17 00:00:44,920 --> 00:00:47,170 It has a make, a model and a year. 18 00:00:47,170 --> 00:00:51,870 It also has attributes like top speed and fuel capacity and maybe it has methods 19 00:00:51,870 --> 00:00:55,340 that let you start and stop the car's engine or drive the car. 20 00:00:55,340 --> 00:00:59,160 Each of those things, each attribute and each method, would be a unit and 21 00:00:59,160 --> 00:01:01,700 each would need at least one test for it. 22 00:01:01,700 --> 00:01:05,200 Since these tests correspond to a unit of code, we call them unit tests. 23 00:01:06,270 --> 00:01:08,990 For example, our car might have a top speed attribute which 24 00:01:08,990 --> 00:01:10,750 should always be set to a number. 25 00:01:10,750 --> 00:01:14,060 We can write a test that sets it to a string like really fast, and 26 00:01:14,060 --> 00:01:16,189 make sure our code raises an exception when that happens. 27 00:01:17,330 --> 00:01:19,160 There are other types of tests too. 28 00:01:19,160 --> 00:01:22,780 Regression tests make sure that previous mistakes don't happen again and 29 00:01:22,780 --> 00:01:26,120 integration tests run your code through a battery of uses to make sure that 30 00:01:26,120 --> 00:01:30,615 a certain process, one that uses multiple units, works from beginning to end. 31 00:01:30,615 --> 00:01:34,015 For example, if you wanted to test the registration flow of a Flask app, 32 00:01:34,015 --> 00:01:36,875 you'd have a test that loads the account creation page, fills out and 33 00:01:36,875 --> 00:01:38,945 submits the form, follows the redirect, and 34 00:01:38,945 --> 00:01:43,085 checks that the user model was created, and that you ended up on the sign in page. 35 00:01:43,085 --> 00:01:45,275 We're gonna focus on unit tests in this course, but 36 00:01:45,275 --> 00:01:48,930 you can use the tools we talk about to write all three kinds of tests. 37 00:01:48,930 --> 00:01:50,510 Okay. Now that we know what a test is, 38 00:01:50,510 --> 00:01:53,760 let's go look at how to write the simplest type of test, a dock test.