Giter Club home page Giter Club logo

elm-test's Introduction

elm-test

Write unit and fuzz tests for your Elm code, in Elm.

Quick Start

Here are three example tests:

suite : Test
suite =
    describe "The String module"
        [ describe "String.reverse" -- Nest as many descriptions as you like.
            [ test "has no effect on a palindrome" <|
                \() ->
                    let
                        palindrome =
                            "hannah"
                    in
                        Expect.equal palindrome (String.reverse palindrome)

            -- Expect.equal is designed to be used in pipeline style, like this.
            , test "reverses a known string" <|
                \() ->
                    "ABCDEFG"
                        |> String.reverse
                        |> Expect.equal "GFEDCBA"

            -- fuzz runs the test 100 times with randomly-generated inputs!
            , fuzz string "restores the original string if you run it again" <|
                \randomlyGeneratedString ->
                    randomlyGeneratedString
                        |> String.reverse
                        |> String.reverse
                        |> Expect.equal randomlyGeneratedString
            ]
        ]

This code includes a few common things:

  • describe to add a description string to a list of tests
  • test to write a unit test
  • Expect to determine if a test should pass or fail
  • fuzz to run a function that produces a test several times with randomly-generated inputs

Check out a more complete example or a large real-world test suite for more.

Running tests locally

There are several ways you can run tests locally:

Here's how set up and run your tests using the CLI test runner.

  1. Run npm install -g elm-test if you haven't already.
  2. cd into the directory that has your elm-package.json
  3. Run elm-test init. It will create a tests directory inside this one, with some files in it.
  4. Copy all the dependencies from elm-package.json into tests/elm-package.json. These dependencies need to stay in sync, so make sure whenever you change your dependencies in your current elm-package.json, you make the same change to tests/elm-package.json.
  5. cd into tests
  6. Run elm-test TestRunner.elm

Edit Tests.elm to introduce new tests.

Happy testing!

Running tests on CI

Here are some examples of running tests on CI servers:

elm-test's People

Contributors

deadfoxygrandpa avatar maxsnew avatar mgold avatar eeue56 avatar xdissent avatar fredcy avatar jaapz avatar avh4 avatar jvoigtlaender avatar laszlopandy avatar turbomack avatar janiczek avatar rtoal avatar rgrempel avatar theuniskotze avatar

Watchers

James Cloos avatar  avatar

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.