Testing the HTTP server
Now that we have all the ingredients to write an HTTP server, it’s time to write some tests. I will only cover some necessary tests in this chapter. If you are curious about which other tests we could write, feel free to check out the code for goldcrest_http_server
, linked in the book’s GitHub repository.
In order to test our HTTP server, we will first need to make two changes to the mix.exs
file, as follows:
- Add Finch to the list of dependencies: This allows us to make HTTP calls to our server’s endpoints.
- Update
elixirc_paths
: This updates the list of paths that need to be compiled as part of the project. Moreover, by defining those paths based on the Mix environment, Mix allows us to compile support modules in the test environment, one of which would be aTestResponder
module.
Let’s go ahead and make these changes:
mix.exs
defmoduleGoldcrestHttpServer.MixProject do use Mix.Project ...