我正在为我的应用程序编写测试用例,并且我的大多数控制器都包含 CRUD 的通用代码,因此我编写了通用宏并在我的控制器中使用它。所有控制器的测试用例都将自动编写。但是我对如何使这个公共代码可重写感到困惑,以便我可以随时重写。
defmodule Qserv.ControllerTest do
defmacro __using__(_options) do
quote location: :keep do
use Qserv.Web.ConnCase, async: true
# this kernel will give me access to current `@model` and `@controller`
use Qserv.KernelTest
describe "#{@controller}.create/2" do
test "All required fields set `required` in model should generate errors that these fields are missing -> One, two, All"
test "Only required fields should create record and match the object"
end
# defoverridable index: 2, I want to override above `describe` completely or/and the included test cases
end
end
end
任何帮助/想法如何实现这一目标?