Test driven development is the best way to write code.
Test driven development means writing tests before writing code.
In this lesson, you're going to learn about test driven developments.
First, open up the following lesson by navigating to this path in your course resources.
A bad design is one code is not modular code that is not modular, performs many tasks at once.
Here is an example of a bad design.
This is code that we wrote in the last section, and the reason why this code is bad is because the
checkout method is performing four tasks at once, which makes it impossible to test.
You can easily get bugs from this code.
Just by looking at it, it's so hard to understand what's going on and trust me, if someone else were
to look at this, they'll say, what the heck happened here?
This code is not scalable.
If someone decides to change anything, it can easily break.
Test driven development is what helps you achieve a modular design.
Test driven development simply means writing tests before writing code.
If a code is easy to test, then it's good code.
So the best way to achieve a modular design is to write tests before writing code.
And there are two parts to test driven development.
First, you have to identify meaningful test cases.
Then you have to write a unit test for each test case first, you write a test that fails, then you
write code to make the test pass, and then you refactor the code if necessary.
Open up the folder for this lesson, there's a text file with a requirement we need to fill fill the
check out process, calculates the receipt and the form of a subtotal tax and total.
The first step is to identify meaningful test cases, think about the requirement and make a list of
test cases we need to test if the subtotal equals the sum of each price.
We also need to test if the tax equals 13 percent of the subtotal.
And then we need to test, if it returns a total, that equals the subtotal plus tax.
That's all for part one of test driven developments, we identified meaningful test cases and in part
two, we're going to write a unit test for each test case.
To recap, test driven development helps achieve a modular design.
There are two parts to test driven development, and in this video we implemented part one, we identified
meaningful test cases.
And Part two is going to be to write a unit test for each test case.
We're going to write a test that fails, write code to make the test pass and then refactor the code
if necessary.