Chapter 10. Driving with tests

 

This chapter covers

  • Understanding unit tests
  • Dealing effectively with dependencies inside tests
  • How to test asynchronous programs
  • How to test behavior
  • Test suites and how to automate your test suite

I saw the best minds of my generation destroyed by madness.

From Howl by Allen Ginsberg

You have to solve harder problems in CoffeeScript today than most people had to solve in JavaScript in the early days. Back then, JavaScript was used to enhance browser applications. Today you’re writing entire applications in CoffeeScript. Writing more of the program means dealing with more of the problems. Writing tests for your programs can help with these problems and save you from losing your mind. Writing the tests first, before writing the programs, is a technique referred to as test-driven development.

If you’ve never done it before, test-driven development can feel uncomfortable, like having your pants on backwards. Be patient and give it some time, though; it might take a while to adjust. If you’ve done test-driven development before but not in CoffeeScript, you’ll be pleasantly surprised at how easy some of the techniques are.

10.1. No tests? Disaster awaits

10.2. How to write tests

10.3. Dependencies

10.4. Testing the asynchronous

10.5. System tests

10.6. Test suites

10.7. Summary