Title: Designing For Testability
1Designing For Testability
2Designing For Testability
- Incorporate design features that facilitate
testing - Include features to
- support test automation at both the unit and
system levels - provide visibility into the programs internal
state and activities - (this allows more specific and accurate bug
reports)
3Verbose output mode
mail -v bret_at_pettichord.com Subject testability
example Sample text. . Cc bret_at_pettichord.com...
Connecting to mx.io.com. via relay...
220-deliverator.io.com ESMTP Sendmail
8.9.3/8.9.3 Fri, 12 Jan 2001 153436 -00 220
Welcome to Illuminati Online, Fnord! EHLO
eris.io.com 250-deliverator.io.com Hello
IDENTwazmo_at_eris.io.com 199.170.88.11, pleased
tu 250-8BITMIME 250-SIZE 5000000 250-DSN 250-ONEX
250-ETRN 250-XUSR 250 HELP MAIL From
SIZE67 250
... Sender ok RCPT To
250 ...
Recipient ok DATA 354 Enter mail, end with
. on a line by itself . 250 PAA07752
Message accepted for delivery bret_at_pettichord.com.
.. Sent (PAA07752 Message accepted for delivery)
Closing connection to mx.io.com. QUIT 221
deliverator.io.com closing connection
Example quoted from Design for Testability by
Bret Pettichord
4Logging events to a file
class Log public const int DEBUG 1
const int INFO 2 const int WARNING
3 const int ERROR 4 const int FATAL
5 // send log output to the console
Log() // send log
output to a file Log(const string
file) // Send log output to a remote
server Log(const string serverIpAddress,
int serverPort) // Only log messages with
priority minPriority void
SetMinPriority(Priority minPriority) // Log
messages with the various priorities
Debug(const string message) Info(const
string message) Warning(const string
message) Error(const string message)
Fatal(const string message)
5Asserts
- Asserts are little test cases distributed
throughout the code - Abortive asserts (crash if assert fails)
- Logging asserts (log message if assert fails)
6The Mock Object design pattern
- Allows a class to be isolated from its
dependencies during unit testing - Supports fault injection
- Cause the software to fail at points where it
normally wouldnt to test error handling code - Example URL Spelling Checker
7Provide automation interfaces
- When possible, test cases should be automated
with test scripts - Test Script a program that runs a batch of
automated test cases and reports the results - User interfaces often do not lend themselves to
automation (especially GUIs) - Programs can provide automation interfaces that
allow test scripts to run commands and query
application state without going through the user
interface - Cmd-line interface (e.g., test-tracker
add-test-plan Word10) - Execute batch command file (e.g., test-tracker
run-batch cmds.txt) - Web service API
8Data generators loaders
- Creating large data sets by hand is not feasible
- Think about trying to manually enter large
amounts of test plan and defect data in Test
Tracker - Data Generator
- A program that generates large amounts of test
data - Configuration parameters let the user shape the
generated data - Data Loader
- A program that loads generated test data into the
application - Example Test Tracker Data Generator Loader