An Experimentalist Approach to Software Testing
Jeff Soules and Brian Ward
Center for Computational Mathematics, Flatiron Institute
Introduction
2
Who are we and why should you listen to us?
3
→ ANYONE can run & interpret
What are we talking about today?
4
Test your oven with a thermometer, not a turkey.
5
“Experimentalist testing” means treating tests as . . .
Test result must depend on your code – a small part of your code – and nothing but your code
6
Experimentalist testing can
7
What you need to follow along today
8
Anatomy of a test
9
What makes a test?
To do a test, you must:
Mnemonic is “arrange, act, assert”
…but the greatest of these is assert
10
One test, one property
Yes, this will lead to lots of tests!
This is not a problem so long as you keep them all fast.
11
Controlled experiments
12
Only test your code
13
Three varieties of bad tests
Those that…
Also fishy: tests that take a huge amount of work to achieve control
14
Live code a test
Follow along at https://github.com/jsoules/experimental-testing-exercises
Folder ‘00’
15
Assumptions and invariants
16
What to assert?
Basic level: confirming expectations
By making assumptions explicit, tests act as a kind of documentation
17
What to assert?
Intermediate level: interactions with external systems
Requires experimental control (e.g. through fakes) and test isolation
18
What to assert?
Conceptual level: system invariants
Sometimes it makes sense to use unrealistic inputs to confirm they are still manipulated properly
19
Exercises
https://github.com/jsoules/experimental-testing-exercises
Folders ‘01’ and ‘02’
20
Experimenting on a�world you control
21
The envy of every experimentalist
22
Tests: beyond pass and fail
Code that’s difficult to test is often also difficult to…
Listen to your pain.
23
Signs that things need to change
24
Responding to common issues
25
Exercises Part 2
https://github.com/jsoules/experimental-testing-exercises
Folders ‘03’ and ‘04’
26
Conclusion
27
Tests are experiments
They should be:
28
You have an advantage
29
Thank you
30
Appendix: Helpful tools
31
Tools to help with testing
Testing framework
32
Tools to help with testing
Assertion libraries
33
Tools to help with testing
Mocking framework
Be careful not to go too far with this ability!
34
Tools to help with testing
Coverage reporting
35