gpt4 book ai didi

unit-testing - 使用 Erlang 进行单元测试时如何自动重新加载模块?

转载 作者:行者123 更新时间:2023-12-04 17:13:10 25 4
gpt4 key购买 nike

我正在使用 Emacs 并试图让我的单元测试工作流程尽可能自动化。我已经设置好了,所以它可以工作,但我必须在 Erlang Shell 识别我的更改之前手动编译我的被测模块或包含测试的模块。

我有两个文件 mymodule.erlmymodule_tests.erl .我想做的是:

  • 将测试用例添加到 mymodule_tests
  • 保存 mymodule_tests
  • 切换到 Erlang Shell
  • 用一行运行测试,例如 eunit:test(mymodule)mymodule_tests:test()
  • 在实际执行测试之前让 Erlang 重新加载 mymodule 和 mymodule_tests

  • 我尝试编写自己的测试方法,但它不起作用。
    -module (mytests).
    -export([test/0]).

    -import(mymodule).
    -import(mymodule_tests).
    -import(code).

    test() ->
    code:purge(mymodule),
    code:delete(mymodule),
    code:load_file(mymodule),
    code:purge(mymodule_tests),
    code:delete(mymodule_tests),
    code:load_file(mymodule_tests),
    mymodule_tests:test().

    我也试过把 -compile(mymodule).进入 mymodule_tests 以查看是否可以在更新 mymodule_tests 时让 mymodule 自动重新加载,但无济于事。

    我也google了很多,但找不到任何相关信息。由于我是 Erlang 的新手,我在想我要么在寻找错误的术语,例如 erlang reload module ,或者您不应该在编译另一个模块时重新加载其他模块。

    最佳答案

    也许 Erlang make可以帮你。

    make:all([load]).

    从文档中读取:

    This function first looks in the current working directory for a file named Emakefile (see below) specifying the set of modules to compile and the compile options to use. If no such file is found, the set of modules to compile defaults to all modules in the current working directory.



    关于“加载”选项:

    Load mode. Loads all recompiled modules.



    还有一个 make:files/1,2它允许您指定要检查的模块列表。

    关于unit-testing - 使用 Erlang 进行单元测试时如何自动重新加载模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4358458/

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