Git Product home page Git Product logo

property-based-testing-demo's Introduction

property-based-testing-demo

Some sample tests I threw together for my talk on Property Based Testing

How to come up with properties

  • Facts​
  • Inverses or duals​
  • Known good (oracle)​

​Practice makes perfect

Facts

  • Something general about the result​

    • (Not) null / negative / empty ​
    • Same result doing it once or multiple times (Idempotent)​
      • “Flag invoice not paid in time”​
      • Add/remove with set semantics​
  • Something about the result in relation to the inputs​

    • (Not) greater / equal / less in length / complexity ​
  • Something about observable side effects​

    • Value has (not) changed ​
    • “Place order increases total order value”​
    • “A delivery increases total stock value”​
  • Something general about the execution ​

    • Should not crash (fuzzing) ​
    • Should (not) throw an exception ​
  • Anything you'd write an assertion about ​

    • A property to verify it is always / never hit ​
    • Design by Contract (Bertrand Meyer) ​

Inverses or duals​

  • Encode/decode​
  • Write/read​
  • Encrypt/decrypt​
  • Serialize/deserialize​
  • Write/delete ​
  • Do/undo​
  • Order/cancel order​
  • Invoice/credit invoice​
  • ...​

Known good (oracle)​ (existing code)​

  • Old (mostly correct) version​
  • 3rd party library​
  • Shell out to some command line tool ​
  • Collect samples from existing app, compare in new app​

Known good (oracle)​ (new code)​

  • You implement two versions​

  • Real + One that is more easily verified to be correct​

  • Idealistic​

    • A Database can be emulated as an in-memory dictionary (Stateful PBT)​
    • maybe not thread safe, insecure, not persistent, all sorts of compromises​
  • Unoptimized​

    • naive implementation​
    • brute-force algorithm
    • single-threaded version​

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.