This document discusses ways to increase testability through code seams. It recommends separating code into functional and non-functional pieces, and extracting the functional pieces. This allows the functional code to be tested in isolation without external dependencies. Specific techniques mentioned include peeling away non-functional layers and slicing functional logic from surrounding code. Examples show how to make code more deterministic and remove reliance on global state, dates, and other uncontrollable variables to improve testability.
5. Why is Testing Hard?
1. Setup
2. Lot’s of paths
3. Global state
4. Lot’s of clutter
5. Environment
6. Uncontrollable
Variables
7. UI
8. Money
9. Dates
10.Mobile
11.Database
12.Integration
13.Wait Times
14.XPath
15.Finding
Elements
16.Timing
17.Failure cases
6. Automated checking is a tactic of testing, and can have considerable value...
…Checking through an API beneath the GUI level can be particularly useful.
In designing such low-level checks, programmers and testers can profitably work
together.
We are more doubtful of automated checking at the GUI level. GUIs are notoriously
fussy.
7. CASE #3: Automated checking.
We wanted to demonstrate full-on automated checking, while at the same time
staying with the FocusWriter example. FocusWriter does not provide an API for
testing, which required us to automate through the GUI, and so the
headaches began.
22. NON-Functional
Get inputs as needed (global state, file,
database…)
Result vary (dates, random, environment)
Store results (global, disk, database, transient)
23. public double calculate(double amount)
{
int step1 = (int) (amount * 2);
double step2 = step1 * 1.5;
return step2;
}
All results out
All inputs in
Deterministic
25. All inputs in?
Deterministic?
public int age(DateTime birthDate)
{
var timeSpan = DateTime.Now -
birthDate;
var age = DateTime.MinValue +
timeSpan;
return age.Year-1;
}
26. public void saveFile(Person info, string fileName)
{
File.WriteAllText(fileName, info.ToString());
}
All results out?
27. WHY FUNCTIONAL IS EASIER FOR TESTS
Unit Test
Production Code
Do
Verify
28. WHY FUNCTIONAL IS EASIER FOR TESTS
Unit Test
Production Code
Do
Verify
Functional Harness
35. Why is Testing Hard?
1. XPath
2. Finding
Elements
3. Global state
4. Dates
5. Failure cases
6. Wait Times
7. Mobile
8. Setup
9. Lot’s of paths
10.Environment
11.Uncontrollable
Variables
12.UI
13.Money
14.Dates
15.Database
16.Integration
17.Finding
Elements
18.Timing