7/16/14 — Test Driven Development

Day 8


Big day today. We began using test-driven development to make a pet sitter application, though by the time we finished it was more like a zombie pet fighting simulator. Test-driven development refers to the process of beginning development by creating tests for your programs to make sure they work. By starting with the test, then making the minimum amount of code necessary to pass the test, then refactoring the code, one can work efficiently and confidently. We used two new modules to help us: mocha and chai. Mocha is a testing framework, which actually runs the tests and outputs the results. Chai is a so-called “assertion library” which works within mocha and allows us to construct our tests in logical and readable ways. By pairing these up with grunt, we have lots of help both with syntax and logic. One your program passes your tests, you can fiddle with it without fear.

Our pet-sitting app gave us more practice with constructors and prototypes, which tied in with our testing. We did what is called unit testing, where each unit that we are testing was a function. Our functions made our pets, and our tests confirmed that our pets had the desired characteristics and behaved the way we wanted.

While TDD takes a lot of planning, it is much more efficient and allows you to be sure you aren’t losing functionality when adding features.

-Mikey