Writing tests for a REST API
Note
The complete code listing for the tests in this section can be found at https://github.com/PacktPublishing/Web-Development-with-Julia-and-Genie/blob/main/Chapter5/TodoMVC/test/todos_API_test.jl.
It’s time to see our API in action by writing a test suite to check all the endpoints and the various scenarios we’ve implemented. Let’s start by adding a new test file for our API:
julia> touch("test/todos_API_test.jl")
Next, we’ll add the test suite to our newly created file:
using Test, SearchLight, Main.UserApp, Main.UserApp.Todos using Genie import Genie.HTTPUtils.HTTP import Genie.Renderers.Json.JSONParser.JSON3 try SearchLight.Migrations.init() catch end cd("..") SearchLight.Migrations.all_up!!() Genie.up() const API_URL = "http://localhost:8000/api/v1/todos" @testset "TodoMVC REST API tests" begin @testset "No todos by default" begin...