I’m not quite sure if nesting is the right expression here, but basically I’m looking to define a parent CaseTemplate
that then my individual DataCase
and ConnCase
modules can depend on.
My original idea was to do this:
defmodule MyApp.CaseTemplate do
use ExUnit.CaseTemplate
setup _tags do
# do stuff
:ok
end
end
defmodule MyApp.DataCase do
use MyApp.CaseTemplate
end
And then I would expect any test using MyApp.DataCase
to run the setup
block defined in MyApp.CaseTemplate
. But it fails with this error:
== Compilation error in file test/support/data_case.ex ==
** (RuntimeError) cannot use ExUnit.Case without starting the ExUnit application, please call ExUnit.start() or explicitly start the :ex_unit app
Just in case there is a better way to achieve my goal, let me share what I was trying to achieve in the first place.
defmodule MyApp.MyTest do
use MyApp.DataCase, async: true
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
I would like to turn the above into this:
defmodule MyApp.MyTest do
use MyApp.DataCase, async: true, vcr: true
And I want it to work for DataCase
, ConnCase
, and any others (without copying the setup
code over).