【问题标题】:Where to put test file for eunit?eunit的测试文件放在哪里?
【发布时间】:2016-06-03 02:14:56
【问题描述】:

我正在尝试测试从磁盘加载文件并对其进行一些操作的功能。我将我的项目分为 src/ 和 test/ 目录。我将测试文件放在 test/ 目录下,并尝试运行加载此文件的单元测试。但是,当使用 rebar 从 IDE (IntelliJ) 或控制台运行测试时,文件似乎不可见。

$ ./rebar eunit
==> traffic-emas (eunit)
input_test: load_from_file_test...*failed*
in function input:load_intersection_definition/1 (src/input.erl, line 40)
in call from input_test:load_from_file_test/0 (test/input_test.erl, line 14)
**error:{badmatch,{error,enoent}}

我应该在哪里放置 eunit 的测试文件以使其可见?

【问题讨论】:

    标签: erlang rebar eunit


    【解决方案1】:

    你可以在你的 eunit 测试中打印出工作目录,看看它认为它在哪里运行:

    debugVal(file:get_cwd())
    

    这应该让您很好地了解放置它的位置。

    【讨论】:

      【解决方案2】:

      Rebar 的documentation suggests 表示您应该在模块本身内放置一个特定于模块的 eunit 测试。例如:

      -ifdef(TEST).
      
      simple_test() ->
          ok = application:start(myapp),
          ?assertNot(undefined == whereis(myapp_sup)).
      
      -endif.
      

      【讨论】:

      • 它没有帮助。测试仍然看不到文件。在 Java 中,我只需将测试文件添加到 src/test/resources 并在单元测试中使用类加载器加载它。 Erlang 有没有类似的东西?
      猜你喜欢
      • 1970-01-01
      • 2022-08-02
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 2011-03-04
      • 2020-06-07
      相关资源
      最近更新 更多