Transcript
Page 1: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Testing Ginormous JavaScript

Apps

Giganotosaurus http://www.jurassicworld-movie.com/

community/forums/topic/31168

2014

#sjsPhilL

Page 2: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Phil @leggetter [email protected]

Caplin Systems !

#sjsPhilL

Page 3: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Discuss testing strategies for big apps (insert gif)

Discussion Track

Oviraptors

#sjsPhilL

Page 4: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Caplin Trader 2 (CT2)!From ~2009

#sjsPhilL

Page 5: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Caplin Trader 2 #sjsPhilL

Page 6: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Caplin Trader 2 Codebase ~2011

• ~1,500 JavaScript files

• ~250,000 LoC

• ~120,000 test LoC

• HTML Templates

• CSS

• Images

• i18n

• Config

#sjsPhilL

Page 7: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Caplin Dev Practices• Multiple contributing teams

• SCRUM - 2 week iteration

• Continuous Integration & Delivery

• Build status displayed on screen

#sjsPhilL

• A focus on Quality Software

https://www.japanla.com/blog.php?blog_id=568

Page 8: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Testing Requirements• Cross-browser IE6+*, Firefox 3.5*+ & Chrome

• Class-level Unit Tests

• Application Acceptance Tests

* Remember this was 2009

#sjsPhilL

Saurophaganax http://www.statesymbolsusa.org/Oklahoma/OklahomaStateFossil.html

Page 9: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 10: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Application ATs• Selenium Tests

• Selenium User-Extensions

• Actions, Accessors/Assertions & Locators

• VM infrastructure for CI

#sjsPhilL

Page 11: Testing Ginormous JavaScript Apps - ScotlandJS 2014

3

3. Launch browser + App

AT Process#sjsPhilL

1

1. Pair Browser + Backend VM2

2. Reset & restart backend services

5

5. Record results

4

4. Execute ATs6

6. Reset backend services

8. Execute next test…

8

7

7. Restart/refresh browser

Page 12: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Test Results• ~1300 UTs

• ~500 ATs

• 50 pairs - VM infrastructure to parallelise tests

#sjsPhilL

• 8 Hours

• We could only run a full suite of tests once per day - at night

• Test results highly unreliablehttp://paintballkitty.spreadshirt.com/sad-dinosaur-A11954669

Page 13: Testing Ginormous JavaScript Apps - ScotlandJS 2014

We Were Doing It Wrong!

https://www.flickr.com/photos/41187064@N03/3809454959/in/gallery-dreamyshade-72157622839898770/

#sjsPhilL

Page 14: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Others may still be doing it wrong.

#sjsPhilL

Page 15: Testing Ginormous JavaScript Apps - ScotlandJS 2014

What’s so Wrong?

#sjsPhilL

Page 16: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Restarting Browser / Relaunching the App

#sjsPhilL

Page 17: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Backend Services #sjsPhilL

Page 18: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Don’t Touch that DOM

#sjsPhilL

Page 19: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Time to Start from Scratch

#sjsPhilL

Page 20: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Improve Speed & Reliability• Full application running + relaunch

• Backend services

• DOM

The long-necked Eodromaeus, or "dawn runner http://video.nationalgeographic.com/video/news/eodromaeus-dinosaur-discovery-vin

#sjsPhilL

Page 21: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 22: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Component/Module/Feature/Blade

#sjsPhilL

Page 23: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 24: Testing Ginormous JavaScript Apps - ScotlandJS 2014

/assets /feature-name

#sjsPhilL

Page 25: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 26: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Workbench #sjsPhilL

Page 27: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 28: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Improve Speed & Reliability• Full application running + relaunch

• Backend services

• DOM

#sjsPhilL

Liopleurodon http://bloodhoundomega.deviantart.com/art/Liopleurodon-312292557

Page 29: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 30: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Setting & Getting Services

• Use a unique identifier for each service

• Register (code or config). Code example:

!

• Get

http://martinfowler.com/articles/injection.html#ADynamicServiceLocator

#sjsPhilL

Page 31: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Fake Services#sjsPhilL

Page 32: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Fake/Stub/Mock Services#sjsPhilL

Page 33: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 34: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Real Services#sjsPhilL

Page 35: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Improve Speed & Reliability• Full application running + relaunch

• Backend services

• DOM

#sjsPhilL

Don’t Touch that DOM

Page 36: Testing Ginormous JavaScript Apps - ScotlandJS 2014

MVVM #sjsPhilL

Page 37: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 38: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Improve Speed & Reliability• Full application running + relaunch

• Backend services

• DOM

#sjsPhilL

Page 39: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Argentinosaurus http://www.walkingwithdinosaurs.com/dinosaurs/detail/argentinosaurus/

The BIG win!

#sjsPhilL

Page 40: Testing Ginormous JavaScript Apps - ScotlandJS 2014

End-to-End Feature Testing

• Testing features in isolation

• Change view model and assert against mocked Service

• Inject fake service, make calls and assert View Model

#sjsPhilL

Page 41: Testing Ginormous JavaScript Apps - ScotlandJS 2014

#sjsPhilL

Page 42: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Need Proof?

Caplin Trader 2 Test suite

>8 Hours

Caplin Trader 3 Test suite

< 30 Minutes

#sjsPhilL

Page 43: Testing Ginormous JavaScript Apps - ScotlandJS 2014

How Do You Test Ginormous JavaScript Apps?

Have an Architecture Built for Testing

1. Components/Widgets/Modules

2. A Services Layer

3. MVVM - Don’t touch that DOM

#sjsPhilL

Supersaurus http://www.cfsl.net/forums/viewtopic.php?f=39&t=19496

Page 44: Testing Ginormous JavaScript Apps - ScotlandJS 2014

Phil @leggetter [email protected]

Caplin Systems !

!

!

@BladeRunnerJS bladerunnerjs.org

#sjsPhilL

Tyrannosaurus Rex http://zorgor.wordpress.com/2012/12/24/cosmic-calendar-dinosaurs/


Top Related