From the course: Test-Driven Development in Django

TDD philosophy and project overview

From the course: Test-Driven Development in Django

Start my 1-month free trial

TDD philosophy and project overview

- [Instructor] Let's talk about test-driven development. What is it? And what's the whole idea behind this philosophy? Well, there's been entire books written about this subject; but when you really boil it down it comes down to this: when you want to build something in software, you first create a test for what you want to have happen. Then you make sure that test fails. And then write the code to pass that test. So you don't write any code. You instead write a failing test, then you write the code to pass that test. This way you know that everything that you have built works correctly and any new features that you add will be safe and working correctly with your code base. So to give you an example of how this will look, we're going to start by creating first just a very simple test. We're going to test if there is a home page. And we write this test first before we write a single line of code. Then we'll go write the code to make this test pass. We'll then move on to writing a second test. We want to make sure that we can see hashes on the home page of this website. And so we'll write the test first that will fail, then we'll write the code for it. As things go on we're going to write even more and more tests. And as we go further and further, we write the test first, then the code. We'll get to the point when we have a lot of different tests making sure that our website is working correctly. Now to give you an idea of visually what it is that we're building, this is the website that we're going to be building. It's going to take any phrase that you type into here. For instance, The Pats will win the Super Bowl, and take that and hash it via a hashing algorithm and spit out the hash for that specific piece of text. If you saw as I was typing out, even if I add some dots dots to the end of this, the hash changes. And if we hit the hash button here, we'll even have a specific URL that we can come back to and visit any time to see the corresponding text.

Contents