What's That Smell? Tidying Up Our Test Code Presented - - PDF document

what s that smell tidying up our test code
SMART_READER_LITE
LIVE PREVIEW

What's That Smell? Tidying Up Our Test Code Presented - - PDF document

T8 Test Automation 2019-05-02 11:15 What's That Smell? Tidying Up Our Test Code Presented by: Angie Jones


slide-1
SLIDE 1

¡ ¡ ¡ ¡ ¡ T8 ¡

Test ¡Automation ¡ 2019-­‑05-­‑02 ¡11:15 ¡ ¡ ¡ ¡ ¡ ¡ ¡

What's ¡That ¡Smell? ¡Tidying ¡Up ¡Our ¡Test ¡ Code ¡ ¡

Presented ¡by: ¡ ¡ ¡

Angie ¡Jones ¡

Applitools ¡ ‘ ¡ ¡ ¡

Brought ¡to ¡you ¡by: ¡ ¡ ¡ ¡

¡ ¡ ¡ ¡ 888-­‑-­‑-­‑268-­‑-­‑-­‑8770 ¡·√·√ ¡904-­‑-­‑-­‑278-­‑-­‑-­‑0524 ¡-­‑ ¡info@techwell.com ¡-­‑ ¡http://www.stareast.techwell.com/ ¡ ¡ ¡ ¡ ¡
slide-2
SLIDE 2

¡

Angie ¡Jones ¡ ¡

Angie ¡Jones ¡is ¡a ¡Senior ¡Developer ¡Advocate ¡who ¡specializes ¡in ¡test ¡automation ¡ strategies ¡and ¡techniques. ¡She ¡shares ¡her ¡wealth ¡of ¡knowledge ¡by ¡speaking ¡and ¡ teaching ¡at ¡software ¡conferences ¡all ¡over ¡the ¡world, ¡as ¡well ¡as ¡writing ¡tutorials ¡and ¡ blogs ¡on ¡angiejones.tech. ¡As ¡a ¡Master ¡Inventor, ¡Angie ¡is ¡known ¡for ¡her ¡innovative ¡and ¡

  • ut-­‑of-­‑the-­‑box ¡thinking ¡style ¡which ¡has ¡resulted ¡in ¡more ¡than ¡25 ¡patented ¡inventions ¡in ¡

the ¡US ¡and ¡China. ¡In ¡her ¡spare ¡time, ¡Angie ¡volunteers ¡with ¡Black ¡Girls ¡Code ¡to ¡teach ¡ coding ¡workshops ¡to ¡young ¡girls ¡in ¡an ¡effort ¡to ¡attract ¡more ¡women ¡and ¡minorities ¡to ¡

  • tech. ¡
slide-3
SLIDE 3

What's That Smell? What's That Smell?

Angie Jones Angie Jones

http://angiejones.tech http://angiejones.tech @techgirl1908 @techgirl1908 Senior Developer Advocate Senior Developer Advocate Applitools, San Francisco, CA, USA Applitools, San Francisco, CA, USA

Tidying Up Our Test Code Tidying Up Our Test Code

slide-4
SLIDE 4

@techg

slide-5
SLIDE 5

a CODE SMELL CODE SMELL is an implementation that is an implementation that violates fundamental design violates fundamental design principles in a way that may principles in a way that may

slide-6
SLIDE 6

APPLICATION APPLICATION UNDER UNDER TEST TEST

@techgirl1908

slide-7
SLIDE 7

JAKE'S JAKE'S CODE CODE BASE BASE

@techgirl1908

slide-8
SLIDE 8

@techgirl1908

LONG CLASS LONG CLASS The purpose of the class is The purpose of the class is multifold. multifold. To find anything, you must To find anything, you must scroll and scroll. scroll and scroll.

slide-9
SLIDE 9

ISSUES ISSUES

@techgirl1908

  • 1. No single responsibility
  • 1. No single responsibility
  • 2. Hard to find things
  • 2. Hard to find things
  • 3. Difficult to maintain
  • 3. Difficult to maintain
slide-10
SLIDE 10

@tech

SEPARATE SEPARATE CONCERNS CONCERNS

slide-11
SLIDE 11

@techgirl1908

LONG METHOD LONG METHOD This guy does it all! This guy does it all! But it makes it hard to know But it makes it hard to know when to call. when to call.

slide-12
SLIDE 12

ISSUES ISSUES

@techgirl1908

  • 1. No single responsibility
  • 1. No single responsibility
  • 2. Confusing for callers
  • 2. Confusing for callers
  • 3. Difficult to read and understan
  • 3. Difficult to read and understan
slide-13
SLIDE 13

@techgirl1908

WE HAVE A PROBLEM! WE HAVE A PROBLEM! How come our second test How come our second test cannot utilize the search cannot utilize the search method? method?

slide-14
SLIDE 14

@tech

SPLIT SPLIT METHODS METHODS

slide-15
SLIDE 15

@techgirl1908

DUPLICATE CODE DUPLICATE CODE When you find yourself When you find yourself coding in haste, coding in haste, it's very tempting it's very tempting

slide-16
SLIDE 16

ISSUES ISSUES

@techgirl1908

  • 1. Any change needed has to
  • 1. Any change needed has to

take place in multiple spots take place in multiple spots

  • 2. Can lead to other smells
  • 2. Can lead to other smells
slide-17
SLIDE 17

@tech

REMOVE REMOVE DUPLICATION DUPLICATION

slide-18
SLIDE 18

FLAKY LOCATOR STRATEGY FLAKY LOCATOR STRATEGY

At this moment, At this moment, your locators work fine. your locators work fine. But can they But can they

slide-19
SLIDE 19

ISSUES ISSUES

@techgirl1908

  • 1. Fragility
  • 1. Fragility
  • 2. Unreliability
  • 2. Unreliability
slide-20
SLIDE 20

@tech

STABILIZE STABILIZE LOCATORS LOCATORS

slide-21
SLIDE 21

@techgirl1908

INDECENT EXPOSURE INDECENT EXPOSURE

  • Too many see you.

Too many see you. Your scope is too wide. Your scope is too wide. All who should know you All who should know you

slide-22
SLIDE 22

ISSUES ISSUES

  • 1. Violates encapsulation (fields)
  • 1. Violates encapsulation (fields)
  • 2. Allows tests to directly access
  • 2. Allows tests to directly access

and manipulate the DOM, and manipulate the DOM, which is not their responsibility which is not their responsibility

slide-23
SLIDE 23

@tech

NARROW NARROW SCOPE SCOPE

slide-24
SLIDE 24

@techgirl1908

INEFFICIENT WAITS INEFFICIENT WAITS The speed of machine The speed of machine is faster than man is faster than man so you slow it down so you slow it down

slide-25
SLIDE 25

ISSUES ISSUES

@techgirl1908

  • 1. Slows down runtime
  • 1. Slows down runtime
  • 2. Different environments may
  • 2. Different environments may

require different wait times require different wait times

slide-26
SLIDE 26

@tech

WAIT WAIT NTELLIGENTLY NTELLIGENTLY

slide-27
SLIDE 27

@techgirl1908

ULTIPLE POINTS OF FAILUR ULTIPLE POINTS OF FAILUR The framework's job The framework's job is to force state, is to force state, not to determine not to determine

slide-28
SLIDE 28

ISSUES ISSUES

@techgirl1908

  • 1. Violates single responsibility
  • 1. Violates single responsibility
  • 2. Limits reusuability
  • 2. Limits reusuability
slide-29
SLIDE 29

@tech

INCREASE INCREASE FLEXIBILITY FLEXIBILITY

slide-30
SLIDE 30

QUESTIONS? QUESTIONS?

@techgirl1908

slide-31
SLIDE 31

What's That Smell? What's That Smell?

Angie Jones Angie Jones

http://angiejones.tech http://angiejones.tech @techgirl1908 @techgirl1908 Senior Developer Advocate Senior Developer Advocate Applitools, San Francisco, CA, USA Applitools, San Francisco, CA, USA

Tidying Up Our Test Code Tidying Up Our Test Code