Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit Test After, First and TDD

Unit Test After, First and TDD

More and more developers are writing unit test. And that's really great. They are a great way to ensure code's correctness. But writing test after is often difficult : code may not be testable, "it works, why bother with test. Let's do real stuff !",... Testing first could be a solution to those problems. TDD goes further. Unit tests do not only test the code, they become a tool to design a better, cleaner and safer code.

This talk has been given at the ITAKE Unconference (http://www.itakeunconf.com)

Antoine

May 30, 2013
Tweet

More Decks by Antoine

Other Decks in Programming

Transcript

  1. DISCLAIMER this is an introduction to unit testing i won't

    talk about : mocking london style vs. chicago integration test and yes, i will do some over exaggeration :)
  2. WHY ? because it's cool ! confidence in your code

    tests tell what your code do testable and tested code often lead to better design the sooner you find problem, the cheaper you'll solve them
  3. COMMON PROBLEMS Why bother with tests, it just works !

    Tests are for people who don’t know how to code ! thecodinglove.com I'm in hurry, I have lot of functionnal to do. I'll write the test later.
  4. (BIGGER ?) PROBLEMS we could have write untestable code we

    have never seen our tests fail ! often, we build test by reverse engeeniring the code
  5. TEST FIRST 1. Think what I want to do. 2.

    Write tests according it. 3. Write code that make all the tests pass. ENJOY.
  6. TEST DRIVEN DEVELOPPEMENT GIT VARIANT 1. Red 2. Green 3.

    git commit 4. Refactor 5. git commit