SlideShare a Scribd company logo
Increase Testability with Code Seams
@LlewellynFalco
SEAMS
BATTERY TESTING
BATTERY TESTING
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
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.
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.
TESTING EDIT PROFILE
TESTING EDIT PROFILE
TESTING EDIT PROFILE
BYPASS LOGIN
https://github.com/login
?return_to=https://github.com/settings/profile
&user_name=isidore
&password=Password123
BYPASS EVERYTHING
https://github.com/EditProfile/
?data={“Name”: “Llewellyn Falco”, “photo”:”http://”….}
Testing Pyramid
Slow
Medium
Fast
1-5%
5-15%
80-90%
TESTING EDIT PROFILE
By.xpath("//div[@class='canvas- graph']//div[contains(text(),Location)][input]/following-sibling::h4”)
TESTING EDIT PROFILE
By.id(”locatation_input”)
DarkFunction Editor Test
1. Open df editor
2. Find File -> Find New -> Find Animation set
3. Navigate to github -> dark function editor ->
Testing Resources -> StarWarsImages -> SWAII.sprites
4. Open
5. Add animation
6. Add animation (1)
7. Add animation (2)
8. Rename animation 1 -> animation a
9. add animation
10 . find animation 3 confirm exists.
DarkFunction Unique Name
DarkFunction Unique Name
Given animation names: animation, animation 2
When I ask for a new name
Then I get animation 3
DarkFunction Editor Test
1. Open df editor
2. Find File -> Find New -> Find Animation
set
3. Navigate to github -> dark function editor
->
Testing Resources -> StarWarsImages ->
SWAII.sprites
4. Open
5. Add animation
6. Add animation (1)
7. Add animation (2)
8. Rename animation 1 -> animation a
9. add animation
10 . find animation 3 confirm exists.
DarkFunction Editor Seams
Functional
Deterministic
All inputs in
All results out
NON-Functional
Get inputs as needed (global state, file,
database…)
Result vary (dates, random, environment)
Store results (global, disk, database, transient)
public double calculate(double amount)
{
int step1 = (int) (amount * 2);
double step2 = step1 * 1.5;
return step2;
}
All results out
All inputs in
Deterministic
public int Advance()
{
return steps++;
}
All inputs in?
All inputs in?
Deterministic?
public int age(DateTime birthDate)
{
var timeSpan = DateTime.Now -
birthDate;
var age = DateTime.MinValue +
timeSpan;
return age.Year-1;
}
public void saveFile(Person info, string fileName)
{
File.WriteAllText(fileName, info.ToString());
}
All results out?
WHY FUNCTIONAL IS EASIER FOR TESTS
Unit Test
Production Code
Do
Verify
WHY FUNCTIONAL IS EASIER FOR TESTS
Unit Test
Production Code
Do
Verify
Functional Harness
public static Output function(inputs)
STEPS
1. Determine functional parts
2. Separate
3. Extract
4. Compare against intention
SEPARATING FUNCTIONAL PIECES
Non-Functional
Functional
List
SEPARATING FUNCTIONAL PIECES
Non-Functional
Functional
List
List2
PEEL
*http://lfal.co/PeelAndSlice
SLICE
return sample
*http://lfal.co/PeelAndSlice
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
Fix: Global State
Resources
www.ApprovalTests.com
21 episode youtube series
#MobProgrammingGuidebook
Contact Information
@LlewellynFalco
http://LlewellynFalco.Blogspot.com
http://www.approvaltests.com

More Related Content

Increase testability with code seams

Editor's Notes

  1. git checkout 8918da8
  2. Both
  3. Both