# Testing

Derw comes with a built-in test runner via `derw test`. The runner is based on [bach](https://github.com/eeue56/bach), a test runner written in TypeScript.

```bash
To run tests, run `derw test` from the package directory
To watch use the --watch flag
  --watch :		Watch Derw files for changes
  --function string:		A particular function name to run
  --file string:		A particular file name to run
  --only-fails :		Only log failing tests
  -h, --help :		This help text
```

## Writing a test

### Naming your file

Your file must have the extension `_test.derw` to be picked up by the test runner.

### Importing the testing functions

Testing functions are provided by the stdlib, which you can install via:

```bash
derw install --name derw-lang/stdlib --version main
```

These can then be imported like&#x20;

```elm
import "./Test" exposing ( equals, notEquals )
```

### Writing your test

A test function should be called `testNameOfTest`, and have the type `a -> void`. Test functions are automatically exported by the compiler.

```elm
testEmptySplit: a -> void
testEmptySplit =
    split "," ""
        |> equals [ "" ]

testSplit: a -> void
testSplit =
    split "," "a,b,c"
        |> equals [
        "a",
        "b",
        "c"
    ]
```

## In-browser tests

When working with html, you may find yourself needing to test a repeated set of actions in the browser - and ensuring the correct data shows up. This can be done via [html-test](https://github.com/derw-lang/html-test) package. It provides both a html element you can embed for results, and a console output. It is currently a work in progress, but if you're curious you can try it out.

![console output](https://342361032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxsLYiKUIBqHoFtXVlAsD%2Fuploads%2FhxLnyEOS8XJwlWXJl9Xc%2Ftest_runner_console_success.gif?alt=media\&token=4a0ef651-bf74-484d-b1ed-1f02c3575ffe)

![web output](https://342361032-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxsLYiKUIBqHoFtXVlAsD%2Fuploads%2FmV3V0rREZESs2KOmBfyQ%2Ftest_runner_web_success.gif?alt=media\&token=e7c4f24b-e81e-4643-be3e-757ed2c3e424)
