Increase testability with code seams

  • View
    1.993

  • Download
    0

  • Category

    Software

Preview:

Citation preview

Increase Testability with Code Seams

@LlewellynFalco

SEAMS

BATTERY TESTING

BATTERY TESTING

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

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

DarkFunction Unique Name

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

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.

DarkFunction Editor Seams

Functional

Deterministic

All inputs in

All results out

NON-FunctionalGet 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

DoVerify

WHY FUNCTIONAL IS EASIER FOR TESTS

Unit Test

Production Code

DoVerify

Functional Harness

public static Output function(inputs)

STEPS

1. Determine functional parts2. Separate3. Extract4. 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. 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

Fix: Global State

Resourceswww.ApprovalTests.com

21 episode youtube series

#MobProgrammingGuidebook

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

Recommended