Can TDD also be used outside developing software?
As an exercise I’d like to see if installing a security camera can be helped by using a TDD approach.
Considering the patterns defined by Kent Beck in Test-Driven Development by Example:
Test List
Write a list of all the tests you know you will have to write
- Should notify when a person is detected in front of house
- Should not notify if an animal or other motion is detected
- Should not trigger for person seen on street
- Should send notification to my phone even when sleep mode is active
- Should record video of person when detected for watching later
Isolate the system under test
It should be possible to run tests on the camera before having it fully installed and mounted on a wall
- Use battery over mains power as:
- Harder to ‘mock out’ mains power
- Can test camera works before wiring in place
- Can experiment and gain rapid feedback on camera positioning
This then indicated features I need in a security camera and what features are not required
Must have
- Battery powered (easier to test positioning that wired camera)
- Person detection (should not send false alarms)
Do not need
- Audible alarm (would be too anoying for neighbours when someone we know walks by)
Test First
To improve the design
By considering all places an intruder could be, this forces me to place the camera in an optimal position and allows me to try out different positions e.g. high up on the garage roof or above the porch without having to commit to installing a power point.
To control scope
By thinking about the tests first I’m forced to consider what the camera should cover
- Should the camera sense motion on the street? – No too many false alarms, so either reposition camera or use zone
- Should the camera notify when I am at home and out? – Yes
- Should a siren sound when a person is detected? No, would be very anoying for neighbours if triggerred when false alarm
Assert first
Start with what you want to test and work backwards.
- I should get notification on my phone – does the camera phone app actually support notifications from camera events?
- Only notify for person events rather than general motion (which would be false alarms outside e.g. tree swaying)
Test data
Consider what test data to use
- An intruder by day (we should add this to our test list)
- An intruder by night (we should also add this to our test list)
- An insect buzzing around the camera (we should also add this to our test list)
Write a failing test first
Some test algorithms which can be tested before the camera is mounted. Simply provide battery power to the camera and try out the following test scenarios. This also means we get to try the camera is working correctly before rather than after installing.
Should send event if person detected
Point camera at a person
Result: fail
Enable people detection on camera app
Result: pass
Should not send phone notification if just motion detected
Enable motion under events
Result: fail (motion is detected)
Disable motion under events
Result: pass (general motion is no longer detected)
Should send phone notification
Result: fail
Enable push notifications
Result: pass