Test-Driven Development

From DevSummit
Jump to: navigation, search
  • Think of a feature
  • Write a failing test
  • Make the test pass
  • Refactor
  • Goto 1
  • It forces you to think about your code before writing it.
  • It forces your code to be testable. Encourages small and discrete code, which is more reusable.
  • It allows you to do refactoring. Maybe you want it to be easier to read, or you come back later and want to do it a different way.
  • TDD helps keep new bugs from being introduced.
  • How to get started? Find a test library for your language. PHP has simpletest and phpunit. Ruby has Rspec and cucumber. Python, Bash, JavaScript has Mocha. Selenium allows you to browser a browser.
  • Unit tests test individual functions seperate from each other.
  • Integration tests test the software stack from the perspective of the user. Testing how lots of things work together.
  • Continuous integration: with every commit every test is run and the whole team can see what's happening.
  • On our team the people writing the code writes the test.
  • In pair programming, you could have one developer write the test and have the other person make it pass.
  • It's important to write good tests. You can make a terrible test suite that slows down development
  • Cucumber allows non-programmers to interact with tests via user stories
  • Mocha is a JavaScript test library. Cooper loves it.
  • Travis CI is a hosted continuous integration service. Cooper loves it.
  • Can run tests headless using jsdom
  • Chai provides helper functions for Mocha

Report back

  • Have confidence to add new things and refactor bad code without breaking old code
  • We proved without a shadow of a doubt that Ruby can add 2 plus 2. And we have a test for it.