1
00:00:00,270 --> 00:00:03,120
Test driven development is the best way to write code.

2
00:00:05,360 --> 00:00:09,500
Test driven development means writing tests before writing code.

3
00:00:12,080 --> 00:00:15,050
In this lesson, you're going to learn about test driven developments.

4
00:00:17,630 --> 00:00:22,550
First, open up the following lesson by navigating to this path in your course resources.

5
00:00:27,800 --> 00:00:34,730
A bad design is one code is not modular code that is not modular, performs many tasks at once.

6
00:00:39,970 --> 00:00:42,220
Here is an example of a bad design.

7
00:00:42,940 --> 00:00:48,070
This is code that we wrote in the last section, and the reason why this code is bad is because the

8
00:00:48,070 --> 00:00:53,490
checkout method is performing four tasks at once, which makes it impossible to test.

9
00:00:54,100 --> 00:00:56,080
You can easily get bugs from this code.

10
00:00:58,090 --> 00:01:03,820
Just by looking at it, it's so hard to understand what's going on and trust me, if someone else were

11
00:01:03,820 --> 00:01:06,560
to look at this, they'll say, what the heck happened here?

12
00:01:07,360 --> 00:01:08,800
This code is not scalable.

13
00:01:08,950 --> 00:01:12,490
If someone decides to change anything, it can easily break.

14
00:01:16,780 --> 00:01:20,680
Test driven development is what helps you achieve a modular design.

15
00:01:21,900 --> 00:01:26,250
Test driven development simply means writing tests before writing code.

16
00:01:26,750 --> 00:01:29,970
If a code is easy to test, then it's good code.

17
00:01:30,100 --> 00:01:35,670
So the best way to achieve a modular design is to write tests before writing code.

18
00:01:39,720 --> 00:01:41,970
And there are two parts to test driven development.

19
00:01:42,450 --> 00:01:45,480
First, you have to identify meaningful test cases.

20
00:01:47,020 --> 00:01:53,470
Then you have to write a unit test for each test case first, you write a test that fails, then you

21
00:01:53,470 --> 00:01:58,510
write code to make the test pass, and then you refactor the code if necessary.

22
00:02:05,560 --> 00:02:10,539
Open up the folder for this lesson, there's a text file with a requirement we need to fill fill the

23
00:02:10,539 --> 00:02:15,130
check out process, calculates the receipt and the form of a subtotal tax and total.

24
00:02:18,770 --> 00:02:24,260
The first step is to identify meaningful test cases, think about the requirement and make a list of

25
00:02:24,260 --> 00:02:29,660
test cases we need to test if the subtotal equals the sum of each price.

26
00:02:38,060 --> 00:02:42,260
We also need to test if the tax equals 13 percent of the subtotal.

27
00:02:43,970 --> 00:02:48,650
And then we need to test, if it returns a total, that equals the subtotal plus tax.

28
00:02:51,010 --> 00:02:56,890
That's all for part one of test driven developments, we identified meaningful test cases and in part

29
00:02:56,890 --> 00:02:59,770
two, we're going to write a unit test for each test case.

30
00:03:02,560 --> 00:03:06,820
To recap, test driven development helps achieve a modular design.

31
00:03:08,080 --> 00:03:13,960
There are two parts to test driven development, and in this video we implemented part one, we identified

32
00:03:13,960 --> 00:03:15,460
meaningful test cases.

33
00:03:16,000 --> 00:03:19,780
And Part two is going to be to write a unit test for each test case.

34
00:03:20,380 --> 00:03:26,530
We're going to write a test that fails, write code to make the test pass and then refactor the code

35
00:03:26,530 --> 00:03:27,430
if necessary.

