So far…

Confess!

Why don’t you write tests?

Ariane 5

Millions of pounds down the drain, some very red faces

Consider Geoffrey Chang…

Three pharma publications in Science, 2001-2005

Letters – Retraction, Science 22 December 2006

And he’s not alone…

He’s really not alone…

What testing gives you

Continued …

Examples of unit testing frameworks

Learning Objectives

Test Driven Development

  1. First write a test

  2. Write code to pass the test

  3. Clean up the code

  4. Repeat

Red, Green, Refactor

Challenge

A colleague of yours has written a function that calculates the running total of all the values in a list, e.g., running([0, 1, 2]) produces the list [0, 1, 3].

Write some unit test functions for it in a test_running.py file (including from running import running at the top), and then use nosetests to see what bugs you can find.

Challenge

  1. Write some unit tests for the fahr_to_kelvin function in temp_conversion.py, which you can find in python-unit-testing/code/temp_conversion.py. Place your unit tests in a new file called test_temp_conversion.py in the python-unit-testing/code directory, and use nose to run the tests. Try and think about tests that could break your code - what are its limits?

  2. Once you’ve completed your tests, add them to version control along with your climate code.

Challenge

Write a function called addnumbers in addnumbers.py that passes the unit tests in test_addnumbers.py.

All addnumbers should do is add together all the numbers in a list and return the result.

OK, What’s the big deal?

Thank You!

/ will be replaced by the title