Write tests in Elm!
Getting Started
Let's start with some example code:
test : Test
test =
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 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:
-
from your terminal via
npm install -g elm-test
- from your browser
- using a custom runner of your own design
Running tests on CI
Here are some examples of running tests on CI servers: