What's That Smell?

Angie Jones

http://angiejones.tech

http://TestAutomationU.com

@techgirl1908

Senior Developer Advocate

Director of Test Automation University

Applitools, San Francisco, CA, USA

Tidying Up Our Test Code

@techgirl1908

a

CODE SMELL

is an implementation that violates fundamental design principles in a way that may slow down development and increase the risk of future issues.

@techgirl1908

APPLICATION

UNDER

TEST

@techgirl1908

JAKE'S

CODE

BASE

@techgirl1908

@techgirl1908

LONG CLASS

 

 

 

The purpose of the class is multifold.

To find anything, you must scroll and scroll.

ISSUES

@techgirl1908

1. No single responsibility

2. Hard to find things

3. Difficult to maintain

@techgirl1908

 

SEPARATE

CONCERNS

 

@techgirl1908

LONG METHOD

 

 

 

This guy does it all!

But it makes it hard to know when to call.

ISSUES

@techgirl1908

1. No single responsibility

2. Confusing for callers

3. Difficult to read and understand

@techgirl1908

WE HAVE A PROBLEM!

 

How come our second test cannot utilize the search method?

@techgirl1908

 

SPLIT

METHODS

 

@techgirl1908

DUPLICATE CODE

 

 

 

 

When you find yourself

coding in haste,

it's very tempting

to copy and paste.

ISSUES

@techgirl1908

1. Any change needed has to take place in multiple spots

2. Can lead to other smells

@techgirl1908

 

REMOVE

DUPLICATION

 

@techgirl1908

FLAKY LOCATOR STRATEGY

 

 

 

 

At this moment,

your locators work fine.

But can they

stand the test of time?

ISSUES

@techgirl1908

1. Fragility

2. Unreliability

@techgirl1908

 

STABILIZE

LOCATORS

 

@techgirl1908

INDECENT EXPOSURE

🛀

Too many see you.

Your scope is too wide.

All who should know you

are the ones inside.

 

ISSUES

@techgirl1908

1. Violates encapsulation

2. Allows tests to directly access and manipulate the DOM, which is not their responsibility

@techgirl1908

 

NARROW

SCOPE

 

@techgirl1908

INEFFICIENT WAITS

 

 

 

 

The speed of machine

is faster than man

so you slow it down

any way you can.

ISSUES

@techgirl1908

1. Slows down runtime

2. Different environments may require different wait times

@techgirl1908

 

WAIT

INTELLIGENTLY

 

@techgirl1908

MULTIPLE POINTS OF FAILURE

 

 

 

 

The framework's job

is to force state,

not to determine

a test's fate.

ISSUES

@techgirl1908

1. Violates single responsibility

2. Limits reusuability

@techgirl1908

 

INCREASE

FLEXIBILITY

 

@techgirl1908

QUESTIONS?

What's That Smell?

Angie Jones

http://angiejones.tech

http://TestAutomationU.com

@techgirl1908

Senior Developer Advocate

Director of Test Automation University

Applitools, San Francisco, CA, USA

Tidying Up Our Test Code

What's That Smell? Tidying Up Our Test Code

By Angie Jones

What's That Smell? Tidying Up Our Test Code

Given a smelly test automation code base which is littered with several bad coding practices, we will walk through each of the smells and discuss why it is considered a violation and demonstrate a cleaner approach.

  • 8,330