Dopplegangers in the web sphere: Decoupling Web Service Components In Test

44
Noah Sussman NYC Testers Meetup at Viacom, November 2014 Dopplegangers! A discussion about Collaborators, Fakes, and Mocks

Transcript of Dopplegangers in the web sphere: Decoupling Web Service Components In Test

Noah Sussman

NYC Testers Meetup at Viacom, November 2014

Dopplegangers!

A discussion about Collaborators,

Fakes, and

Mocks

✤ jq: JSON query language

✤ Python SimpleHTTPServer

✤ JSON API spoofing

✤ Chrome Inspector

✤ The BASE tag — forgotten relic of ancient power!

Simple Tools For Complicated Tasks

✤ Debugging is much harder than writing code in the first place.

✤ Automated tests that you cannot debug are worse than useless: such tests provide a FALSE sense of confidence.

Why not build a framework?

Ironies of automation

✤ Testing is harder than writing the code under test

✤ Testing is yet another layer(s) of complexity

✤ Tests that are opaque dramatically increase cost while adding zero value

✤ There is NO value in flaky, hard-to-debug tests

✤ rm -rf * SERIOUSLY

jq the JSON parser

✤ transform any data source into JSON

✤ transform JSON into executable code

✤ create ETL pipelines

✤ unlimited POWER

jq: SQL queries for JSON

✤ Compiled C binary, just like find, grep and awk

✤ Does one thing and does it well

✤ Can transform any text input into valid JSON

✤ Only emits valid JSON. Anything else is a fatal error.

✤ Extremely fast, if you’re into that ;-)

Convert plain text logs to JSON.

Convert plain text logs to JSON.

Validate data integrity.

JSON Schema Validation

Chrome Inspector Network Tab

✤ View all the assets that were loaded by the browser

✤ Watch XHR requests happen in real time

✤ Download cached copies of JSON API responses!

Visual Inspection

✤ Examine HTTP conversations in the Net tab

✤ Locate JSON feeds

✤ Download JSON documents

✤ “Replay” documents in test using SimpleHTTPServer

Sufficiently advanced fakes…

✤ …are indistinguishable from production services

A Fake Chat Bot

✤ 61 lines of HIGHLY LEGIBLE bash and jq

✤ Does one thing and does it well

✤ Does NOT provide most chatbot features

✤ Indistinguishable from a chatbot in practice

✤ Jenkins plugins are integral. Break HipChat you might break Jenkins!

✤ No matter how hard the bot goes down, you only ever have to debug 61 lines to restore your mission-critical Jenkins status announcements!

Why not use a framework?

A chat bot is a stack

Jenkins JSON API

That’s it! It acts like a bot (sort of).

A New Jersey solution in the wild!

✤ Simplicity and design are equally important until you have to pick one; then pick simplicity.

✤ Modern business practices assume that there is no functional upper limit on system complexity.

MIT vs. New Jersey! a.k.a “worse is better”

The BASE tag

✤ Overrides the root URL of an HTML page.

✤ Saturate local HTML pages with production assets!

Handling plutonium: get ready for it

✤ Eventually your automation will detect a widespread antipattern.

✤ Since your automation made the discovery, you will by definition know the nature of the bug(s) better than anyone else.

✤ It’s SUPER scary to factor out a widespread pattern.

✤ tl;dr: you’ll want to fix it, though it’ll be hard.

Thanks!

✤ I’ll take a few questions now…

✤ Follow me on twitter: @noahsussman