testing

Testing with Mocks

published on
The situation was that, I needed to mock multiple external service within my application in order to test my application. These external services are being consumed using HTTPPoison the popular elixir http client. The mock is achieved using the Mock library # ~/multi_mocks.exs Import Mock #Mock multiple functions of the same module test "Test special service that will call other supporting endpoints" do with_mock( HTTPoison, post!: fn endpoint_a, _, _ -> %HTTPoison. Read More...

Testing a phoenix controller

published on
The snippet below is a phoenix framework controller test defmodule PaymentServiceWeb.Controllers.PaymentTest do use ExUnit.Case, async: false use Plug.Test alias PaymentServiceWeb.Router @tag endpoint: true test "service health check" do conn = conn(:get, "/api") response = Router.call(conn, @opts) assert %Plug.Conn{resp_body: body} = response end end Explanation The test above is going to test an api endpoint, and the simple assertion is just to ensure that a %Plug.Conn struct is received as the response. Read More...