Reputation: 4077
In import_test.exs
file, there is function as follows:
# @tag :external
test "extract_csv, header_only/1" do
file = Path.join([:code.priv_dir(:mirror), "test", "head_only.csv"])
batch = %Imports.Batch{internal_csv_path: file, importer_id: 1}
Imports.extract_csv(batch)
products = Imports.list_products()
IO.inspect(products, label: "before")
assert products == []
end
how to call it directly in shell? If running mix test --only external
, the db update result won't be viewed because the test
environment's automatically rollback operation after every unit test.
Now I copy the every line of test
into iex
shell. Is it necessary?
when compile imports_test.exs
, it gives the following message.
c("test/mirror/imports_test.exs")
** (CompileError) test/mirror/imports_test.exs:2: module Mirror.DataCase is not loaded and could not be found
(elixir 1.13.4) expanding macro: Kernel.use/1
test/mirror/imports_test.exs:2: Mirror.ImportsTest (module)
test module header is as follows:
defmodule Mirror.ImportsTest do
use Mirror.DataCase
alias Mirror.Imports
Upvotes: 2
Views: 337
Reputation: 120990
Assuming this function is located in test/my_test.ex
file, in the module named MyTest
, you might do the following.
iex|💧|1 ▸ c "test/my_test.exs"
[SiblingsTest]
iex|💧|2 ▸ MyTest.__info__(:functions)
[
__ex_unit__: 0,
__ex_unit__: 2,
"test extract_csv, header_only/1": 1,
...
]
That means, you might apply it as
apply(MyTest, :"test extract_csv, header_only/1", [%{}])
The last argument would be context. Please note, that neither setup/1
nor any other callback would not have been called.
Upvotes: 3