2016-02-21 78 views
1

我試圖測試從磁盤加載文件並對其進行一些操作的函數。我將我的項目分爲src /和test /目錄。我把test文件放在test /目錄下,並嘗試運行加載這個文件的單元測試。但是,從IDE(IntelliJ)或使用鋼筋的控制檯運行測試時,文件似乎不可見。哪裏可以放置eunit的測試文件?

$ ./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的測試文件使其可見?

回答

1

您可以在eunit測試打印出的工作目錄,看看它認爲它的運行:

debugVal(file:get_cwd()) 

這應該給你把它放在哪裏是個好主意。

-1

Rebar's documentation suggests您應該在模塊本身內部放置模塊特定的eunit測試。例如: -

-ifdef(TEST). 

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

-endif. 
+0

它沒有幫助。測試仍然無法看到文件。在Java中,我只需將測試文件添加到src/test/resources中,並在Unit Test中使用classloader加載它。 Erlang有類似的東西嗎? – slakomy

相關問題