Stop writing tests (so much)

From Automation to Autogeneration

Let's fix this

And this

And this

And this

Requirements

Code

Tests

LOC

Time

Lots of Unit Tests

Verify that you are a developer that knows how to code

What if tests can be generated

without being written?

What if tests can be regenerated

without being rewritten?

Model Based Testing

Automatic Test Generation

Loading

Success

Resolve

Initial state

States

Events

Transitions

Final State

Failed

REJECT

RETRY

State machines

Requirements

Abstract Model

Given [precondition]

precondition

postcondition

action

when [action]

then [postcondition]

Executable Tests

🔍

🔍

💥

1. Create a model

1. Create a model

2. Generate abstract tests

1. Create a model

2. Generate abstract tests

3. Make them real

🖱

⌨️

💥

Precondition

Postcondition

1. Create a model

2. Generate abstract tests

3. Make them real

4. Execute the tests

1. Create a model

2. Generate abstract tests

3. Make them real

4. Execute the tests

Model regenerates tests

5. Profit (seriously)

How was your experience?

𝘅

Good

Bad

Tell me why?

𝘅

Submit

Thanks for your feedback.

𝘅

Close

Ain't nothin' but a heartache

import { Machine } from 'xstate';

const feedbackMachine = Machine({
  id: 'feedback',
  initial: 'question',
  states: {
    question: {
      on: {
        CLICK_GOOD: 'thanks',
        CLICK_BAD: 'form',
        CLOSE: 'closed'
      }
    },
    form: {
      on: {
        SUBMIT: 'thanks',
        CLOSE: 'closed'
      }
    },
    thanks: {
      on: {
        CLOSE: 'closed'
      }
    },
    closed: {
      type: 'final'
    }
  }
});

question

thanks

form

closed

CLICK_GOOD

CLICK_BAD

SUBMIT

CLOSE

CLOSE

CLOSE

import { getSimplePaths } from '@xstate/graph';
import { feedbackMachine } from '../path/to/feedbackMachine';

const shortestPaths = getShortestPaths(feedbackMachine);

question

question

form

question → CLICK_BAD form

thanks

question → CLICK_BAD form SUBMIT → thanks

question → CLICK_GOOD → thanks

closed

question → CLOSE→ closed

question → CLICK_BAD → form → CLOSE → closed

question → CLICK_GOOD → thanks → CLOSE → closed

question → CLICK_BAD → form → SUBMIT → thanks → CLOSE → closed

A

B

C

D

E

Shortest paths

A → C → E

A

B

C

D

E

Shortest paths

A → B → D → E

Weighted: Dijkstra's algorithm

A

B

C

D

E

Simple paths

A → C → E

A → B → D → E

A → B → C → E

A → C → B → D → E 

TEST

npm install @xstate/test

GraphWalker

HARDER

BETTER

FASTER

STRONGER

Learning curve

Limited tooling

No guarantees

Model might be wrong

(but that's your fault)

Requirements integrity

Test generation

Flexibility

Reduce costs/time

Efficiency

Edge case discovery

Maintenance

Implementation agnostic

Make your code

model-driven

generate

tests

docs

prototypes

do more.

Thank you CSE!

Write Fewer Tests!

By David Khourshid

Write Fewer Tests!

CSE Offsite 2019

  • 3,253