Giter Site home page Giter Site logo

architecture-test's Introduction

ArchitectureTest

Terminal screencast of usage

tl;dr: Fuzz-test your update function with random List Msgs!

(Click on the diagram below for full size!)

High-level diagram

To do this, you create a Msg fuzzer (and possibly a Model fuzzer) and plug it in test functions exposed here!

  • Here are example Models with test suites showing how to write these kinds of tests.
  • Richard Feldman has a simpler library rtfeldman/test-update with the same purpose - give it a look!
  • A talk about this topic was presented at Elm Europe 2017.
  • For more discussion, see this issue of elm-test.

FAQ

Can Elm enumerate over your Msg type automatically?

No, it cannot (as of version 0.18). You will have to specify your Msg fuzzers by hand:

cancel : Fuzzer Msg
cancel =
    Fuzz.constant Cancel

addCoins : Fuzzer Msg
addCoins =
    Fuzz.intRange 0 Random.maxInt
        |> Fuzz.map AddCoins

-- some other Msg fuzzers... and then, combine them:

allMsgs : Fuzzer Msg
allMsgs =
    Fuzz.oneOf
        [ cancel
        , addCoins
        , buy
        , takeProduct
        ]

How can I focus my Msgs (prefer some of them more than others?)

Right, so Fuzz.oneOf gives all the options the same probability of being chosen. It internally uses Fuzz.frequency, which you can use too and specify your own probabilities!

preferAdding : Fuzzer Msg
preferAdding =
    Fuzz.frequency
        [ (1, cancel)
        , (10, addCoins)
        , (1, buy)
        , (1, takeProduct)
        ]

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.