increase testability with code seams

39
Increase Testability with Code Seams @LlewellynFalco

Upload: llewellyn-falco

Post on 15-Apr-2017

1.993 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Increase testability with code seams

Increase Testability with Code Seams

@LlewellynFalco

Page 2: Increase testability with code seams

SEAMS

Page 3: Increase testability with code seams

BATTERY TESTING

Page 4: Increase testability with code seams

BATTERY TESTING

Page 5: Increase testability with code seams

Why is Testing Hard?1. Setup2. Lot’s of paths3. Global state4. Lot’s of clutter5. Environment6. Uncontrollable

Variables

7. UI8. Money9. Dates10.Mobile11.Database12.Integration

13.Wait Times14.XPath15.Finding

Elements16.Timing17.Failure cases

Page 6: Increase testability with code seams

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.

Page 7: Increase testability with code seams

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 theheadaches began.

Page 8: Increase testability with code seams

TESTING EDIT PROFILE

Page 9: Increase testability with code seams

TESTING EDIT PROFILE

????

Page 10: Increase testability with code seams

TESTING EDIT PROFILE

Page 11: Increase testability with code seams

BYPASS LOGIN

https://github.com/login?return_to=https://github.com/settings/profile&user_name=isidore&password=Password123

Page 12: Increase testability with code seams

BYPASS EVERYTHING

https://github.com/EditProfile/?data={“Name”: “Llewellyn Falco”, “photo”:”http://”….}

Page 13: Increase testability with code seams

Testing Pyramid

Slow

Medium

Fast

1-5%

5-15%

80-90%

Page 14: Increase testability with code seams

TESTING EDIT PROFILE

By.xpath("//div[@class='canvas- graph']//div[contains(text(),Location)][input]/following-sibling::h4”)

Page 15: Increase testability with code seams

TESTING EDIT PROFILE

By.id(”locatation_input”)

Page 16: Increase testability with code seams

DarkFunction Editor Test1. Open df editor2. Find File -> Find New -> Find Animation set3. Navigate to github -> dark function editor -> Testing Resources -> StarWarsImages -> SWAII.sprites4. Open5. Add animation6. Add animation (1)7. Add animation (2)8. Rename animation 1 -> animation a9. add animation10 . find animation 3 confirm exists.

Page 17: Increase testability with code seams

DarkFunction Unique Name

Page 18: Increase testability with code seams

DarkFunction Unique NameGiven animation names: animation, animation 2When I ask for a new name Then I get animation 3

Page 19: Increase testability with code seams

DarkFunction Editor Test1. Open df editor2. Find File -> Find New -> Find Animation set3. Navigate to github -> dark function editor -> Testing Resources -> StarWarsImages -> SWAII.sprites4. Open5. Add animation6. Add animation (1)7. Add animation (2)8. Rename animation 1 -> animation a9. add animation10 . find animation 3 confirm exists.

VS.

Page 20: Increase testability with code seams

DarkFunction Editor Seams

Page 21: Increase testability with code seams

Functional

Deterministic

All inputs in

All results out

Page 22: Increase testability with code seams

NON-FunctionalGet inputs as needed (global state, file, database…)

Result vary (dates, random, environment)

Store results (global, disk, database, transient)

Page 23: Increase testability with code seams

public double calculate(double amount){

int step1 = (int) (amount * 2);double step2 = step1 * 1.5;return step2;

}

All results out

All inputs in

Deterministic

Page 24: Increase testability with code seams

public int Advance(){

return steps++;}

All inputs in?

Page 25: Increase testability with code seams

All inputs in?

Deterministic?public int age(DateTime birthDate){

var timeSpan = DateTime.Now - birthDate;

var age = DateTime.MinValue + timeSpan;

return age.Year-1;}

Page 26: Increase testability with code seams

public void saveFile(Person info, string fileName){

File.WriteAllText(fileName, info.ToString());}

All results out?

Page 27: Increase testability with code seams

WHY FUNCTIONAL IS EASIER FOR TESTS

Unit Test

Production Code

DoVerify

Page 28: Increase testability with code seams

WHY FUNCTIONAL IS EASIER FOR TESTS

Unit Test

Production Code

DoVerify

Functional Harness

Page 29: Increase testability with code seams

public static Output function(inputs)

Page 30: Increase testability with code seams

STEPS

1. Determine functional parts2. Separate3. Extract4. Compare against intention

Page 31: Increase testability with code seams

SEPARATING FUNCTIONAL PIECES

Non-Functional

Functional

List

Page 32: Increase testability with code seams

SEPARATING FUNCTIONAL PIECES

Non-Functional

Functional

List

List2

Page 33: Increase testability with code seams

PEEL*http://lfal.co/PeelAndSlice

Page 34: Increase testability with code seams

SLICE

return sample

*http://lfal.co/PeelAndSlice

Page 35: Increase testability with code seams

Why is Testing Hard?1. XPath2. Finding Elements3. Global state4. Dates5. Failure cases6. Wait Times7. Mobile

8. Setup9. Lot’s of paths10.Environment11.Uncontrollable

Variables12.UI13.Money

14.Dates15.Database16. Integration17.Finding Elements18.Timing

Page 36: Increase testability with code seams

Fix: Global State

Page 37: Increase testability with code seams

Resourceswww.ApprovalTests.com

21 episode youtube series

Page 38: Increase testability with code seams

#MobProgrammingGuidebook

Page 39: Increase testability with code seams

Contact Information@LlewellynFalcohttp://LlewellynFalco.Blogspot.comhttp://www.approvaltests.com