Testing

Please open notebook rrsepython-s2r1.ipynb

Introduction

A few reasons not to do testing

Sensibility Sense
It's boring Maybe
Code is just a one off throwaway As with most research codes
No time for it A bit more code, a lot less debugging
Tests can be buggy too See above
Not a professional programmer See above
Will do it later See above

A few reasons to do testing

Not a panacea

Trying to improve the quality of software by doing more testing is like trying to lose weight by weighting yourself more often.

Tests at different scales

Level of test Area covered by test
Unit testing smallest logical block of work (often < 10 lines of code)
Component testing several logical blocks of work together
Integration testing all components together / whole program


Always start at the smallest scale!
If a unit test is too complicated, go smaller.

Legacy code hardening

setup input
run program
read output
check output against expected result

Testing vocabulary

Branch coverage:

if energy > 0:
    ! Do this
else:
    ! Do that

Is there a test for both energy > 0 and energy <= 0?

Next: Reading - Designing Tests