ElixirでPlugのテストです。use Plug.Testというモジュールを使うらしい。
/my_plug/test/my_plug_test.exs
参考サイト
Testing plugs(Plug)
ElixirでのPlugの基本
ElixirでのPlugの基本(その2)
ElixirでのPlugの基本(その3)「Supervised handlers」
/my_plug/test/my_plug_test.exs
defmodule MyPlugTest do
use ExUnit.Case, async: true
use Plug.Test
@opts MyRouter.init([])
test "returns index" do
# Create a test connection
conn = conn(:get, "/")
# Invoke the plug
conn = MyRouter.call(conn, @opts)
# Assert the response and status
assert conn.state == :sent
assert conn.status == 200
assert conn.resp_body == "index page"
end
test "returns hello world" do
# Create a test connection
conn = conn(:get, "/hello")
# Invoke the plug
conn = MyRouter.call(conn, @opts)
# Assert the response and status
assert conn.state == :sent
assert conn.status == 200
assert conn.resp_body == "world"
end
test "the truth" do
assert 1 + 1 == 2
end
end
$ mix test
Finished in 0.06 seconds (0.06s on load, 0.00s on tests)
3 tests, 0 failures
参考サイト
Testing plugs(Plug)
ElixirでのPlugの基本
ElixirでのPlugの基本(その2)
ElixirでのPlugの基本(その3)「Supervised handlers」