gpt4 book ai didi

elixir - 在 Elixir 中,将测试文件与其相关模块放在一起

转载 作者:行者123 更新时间:2023-12-02 03:06:08 25 4
gpt4 key购买 nike

在 Elixir 中是否可以将我的测试模块与他们正在测试的模块放在同一目录中?

典型的 Elixir 项目具有如下结构:

project
|-- lib
| `-- my_module.ex
`-- test
|-- my_module_test.exs
`-- test_helper.exs

在编写节点项目时,我喜欢将测试模块放在他们正在测试的模块旁边。这可以使用 Jest 等工具轻松配置:

project
|-- lib
| |-- my_module.ex
| `-- my_module.test.exs
`-- test
`-- test_helper.exs

Elixir/Exunit 中是否可以有类似的设置?

最佳答案

好的,为了 future 的访问者,我会将其作为答案。

混合文档 explicitly states

Invoking mix test from the command line will run the tests in each file matching the pattern *_test.exs found in the test directory of your project.

看起来 ExUnit 作者强烈反对开发人员将测试放在其他地方。正如 @harryg 发现的那样,这仍然是可能的。 project 设置有 tests_path 变量 that is checked for where tests are to be found (以及 test_pattern 表示模式,)默认为 "test" 并且分别是“*_test.exs”

要将其重置为其他值,只需更新 project 回调并添加以下两行即可:

  def project do
[
app: @app,
version: @version,
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
...
test_paths: ".",
test_pattern: "*_test.exs" # or something else
]
end

关于elixir - 在 Elixir 中,将测试文件与其相关模块放在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51541363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com