and failing fast

Quality coding #4

Dan Fitch



What does it mean?

Testable by humans

Testable by code!

Failing fast

Why fail?

Can't learn without failing!

Pop quiz

Bash version

Bash output

Better bash ways?

set -e

Check value of $?

Python version

Python output

Better python ways?

Check return value

Use a function

Best: use subprocess.run(args, check=True)

Unit testing

In general

  1. Find small pieces or functions
  2. Write one or more tests to confirm it does what you think it does
  3. Run tests whenever you make changes

TDD (test-driven development)

  1. Write test
  2. Make sure it fails
  3. Make it pass

Example test suite: JS

Example test suite: Python


Not magic

How to apply to task code?

  1. E-prime: you can't
  2. Psychopy: very difficult
  3. JS frameworks: tricky, but possible

Unit test the hard parts

How to apply to glue code and pipelines?