Testing testing gotta get down on testing

VanJS

July 16th, 2025

Gavin Mogan

Senior Software Engineer at Digital Ocean. Digital Ocean Mascot, Sammy the Shark, holding a heart ballon

https://www.gavinmogan.com

Avatar

Testing?

means of testing: such as

(1) something (such as a series of questions or exercises) for measuring the skill, knowledge, intelligence, capacities, or aptitudes of an individual or group

(2) a procedure, reaction, or reagent used to identify or characterize a substance or constituent

Merriam Webster

Why should you listen to me?

  • I'm here right now!
  • I've made so many mistakes so you don't have to.
  • Worked at several testing compainies.
  • Was on the board for the open source project Jenkins.
  • Been interviewed about testing on podcasts.

What is it good for?

Living Documentation

  • Why does this function return this?
  • What does real world input look like?

Confidence

  • in future changes
  • current changes
  • refactors

What is testing?

Produced by ChatGPT
The Practical Test Pyramid - Martin Fowler

Gavin's testing pyramid?

  • End To End (e2e) tests (aka integration).
  • Mock e2e tests.
  • "Simple" tests.

End to End Tests

"everything real"

  • Actual Client (Browser)
  • Actual Server
  • Real Credentials
  • Actual Database

Examples

  • Entire application

E2E Strengths

  • Makes sure everything works together
  • Closest to end-user behaviors
  • External changes get highlighted

E2E Weaknesses

  • Hard to setup and control state
  • Slowest
  • Flakey

E2E Tools

Browser

  • Playwright
  • Cypress
  • Selenium
  • TestCafe

Mobile

  • Appium

Mocked E2E Tests

Mocked E2E Tests

A hybrid model between full e2e and isolated testing.

Call mocks or fake endpoints to emulate.

Bigger units of work, but also more control.

Examples

  • Login Form
  • REST server endpoint

Mocked - Strengths

  • Can control states
  • Easy to spot new dependencies

Mocked - Cons

  • Have to implement and maintain mocks or sample data
  • Can lead to complex mocks that dont actually test things
  • Can easily break if your code uses globals
  • Can hide external systems changing

Mocked - Tools

Probably can include most e2e and unit test suites too

Javascript

  • Nock
  • Jest
  • Sinon
  • Mock Service Worker

Golang

  • Gomock
  • Counterfeiter
  • Mockery

"Regular"/"Unit" tests

Focus on small units of work.

Make them fast, and have a ton of them

Examples

  • Sum function
  • Convert one data model to another
  • Password strength component

Unit Tests - Strengths

  • Fast
  • Just focus on input and output
  • Easy to write
  • Easy to maintain
  • Can be run in parallel (unless you use globals 😭)
  • Indirectly can lead to maintainable and understandable code

Unit Tests - Cons

  • Doesnt break when external systems change
  • Devevelopment before testing often involves coming back and redoing development to make it testable
  • Globals can make it hard to isolate

Unit Tests - Tools

A very non exhaustive list

Javascript

  • Jest
  • Mocha
  • Jasmine

Golang

  • Go test

Python

  • Py.test
  • pyunit

Ruby

  • rspec

Getting Started

Getting started pt2

You don't need a formal framework


            const Users = require('./models/users.js');

            Users.createUser({
              username => "zoidberg",
              password => "doctor"
            }).then(function(user) {
              console.log($user);
            });
          

Getting started pt3

Testing every scenario

Start with bugs

  • Already include reproduction steps
  • Already need to have a way to say its done

Getting Started for real

Aka frameworks and automation

Install tooling


            $ npm install --save-dev jest
          

sum.test.js


            const sum = (a, b) => a+b;

            test('adds 1 + 2 to equal 3', () => {
              expect(sum(1, 2)).toBe(3);
            })
          

Success!


            $ jest sum.test.js
          
Jest output showing the test passed

Automate it!

Code Servers

  • Commit hooks
  • Github / Gitlab actions

SaaS

  • Circle CI
  • Cloudbees (Jenkins)

Self-Hosted

  • Jenkins
  • Tekton

Github Actions

Github actions showing a test run
https://github.com/halkeye/demo-jest-github-actions

Tools I didn't know where to put

  • Chromatic - Visual regression testing (SaaS but i've seen open source versions)
  • Storybook - Component library

Storybook - Component library

Storybook screenshot showing a component library https://storybook.js.org/ https://jenkins-io-components.netlify.app/

Chromatic - Visual regression testing

Chromatic screenshot showing a visual regression test

The End

Gavin Mogan

Senior Software Engineer at Digital Ocean. Digital Ocean Mascot, Sammy the Shark, holding a heart ballon

https://www.gavinmogan.com

Avatar