elixir_script v0.32.1 ElixirScript.Test View Source
Unit Testing Framework for ElixirScript.
Requires node.js 8.3.0 and above
Uses assertions from ExUnit as well as has a similar api to ExUnit with a few differences
Example
An basic setup of a test. Modified from ExUnit’s example
# File: assertion_test.exs
# 1) Create a new test module (test case) and use "ElixirScript.Test".
defmodule AssertionTest do
use ElixirScript.Test
# 2) Use the "test" macro.
test "the truth" do
assert true
end
end
To run the test above, use the ElixirScript.Test.start/1 function, giving it the path to the test
ElixirScript.Test.start("assertion_test.exs")
Integration with Mix
To run tests using mix, run mix elixirscript.test. This will run all tests in the test_elixir_script directory.
Callbacks
ElixirScript defines the following callbacks
- setup/1
- setup/2
- setup_all/1
- setup_all/2
- teardown/1
- teardown/2
- teardown_all/1
- teardown_all/2
The setup and setup_all callbacks work exactly as they would in ExUnit. Instead of having an on_exit callback,
ElixirScript.Test has teardown callbacks. teardown is called after each test and teardown_all after all tests
in the file have run.
defmodule AssertionTest do
use ElixirScript.Test
# run before test
setup do
admin = create_admin_function()
[admin: admin]
end
test "the truth", %{admin: admin} do
assert admin.is_authenticated
end
# run after test
teardown, %{admin: admin} do
destroy_admin_function(admin)
end
end
Link to this section Summary
Functions
Runs tests found in the given path. Accepts wildcards
Link to this section Functions
Runs tests found in the given path. Accepts wildcards