如何使用钢筋来创建一个具有eunit测试的erlang模块? [英] how to use rebar to create an erlang module with an eunit test?
问题描述
我已经尝试了以下内容:
mkdir erlangscratch
pre>
cd erlangscratch
rebar create template = simplemod modid = erlangscratch
编辑'test / erlangscratch_tests.erl'看起来像这样:
-module(erlangscratch_tests)。
-include_lib(eunit / include / eunit.hrl)。
%这应该失败
basic_test_() - >
?assert(1 =:= 2)。
执行测试:
snowch @ tp:〜/ erlangscratch $ rebar co eu
==> erlangscratch(compile)
==> erlangscratch(eunit)
测试没有执行,但似乎代码不是
以下是我的文件夹的内容:
snowch @tp:〜/ erlangscratch $ tree。
。
├──src
│└──erlangscratch.erl
└──测试
└──erlangscratch_tests.erl
2个目录,2个文件
问题:我错过了哪些步骤? p>
更新:
接受的答案
basic_test _
函数需要重命名,并且src / erlangscratch.app.src丢失,因此我创建了以下内容:{application,erlangscratch,
[
{description,An Erlang erlangscratch library},
{vsn ,1},
{modules,[
erlangscratch
]},
{registered,[]},
{applications,[
kernel ,
stdlib
]},
{env,[]}
]}。
解决方案您正在将测试与测试生成器。
简而言之,第二个应该返回乐趣或乐趣的列表。您可以在测试名称末尾和
_
和宏的开头区分_
。
简单的解决方案将使用
basic_test() - >
?assert(1 =:= 2)。
或
basic_test_() - >
?_assert(1 =:= 2)。
根据您的需要,您了解的更好。
$ bEDIT 共享文件夹结构
似乎钢筋不认识你作为 OTP应用程序的项目。你可能只是简单的
.app.src
文件。例如:{application,myapp,
[
{description,},
{vsn,1},
{registered,[]},
{applications,[
kernel,
stdlib
]},
{env,[]}
]}。
由于钢筋能够为您生成一个,您只需调用
钢筋创建应用程序
或扩展现有模板之一。My goal is quite simple; while I am learning Erlang, I would like to use rebar to create a basic module with an eunit test:
I have tried the following:
mkdir erlangscratch cd erlangscratch rebar create template=simplemod modid=erlangscratch
Edit the 'test/erlangscratch_tests.erl' to look like this:
-module(erlangscratch_tests). -include_lib("eunit/include/eunit.hrl"). % This should fail basic_test_() -> ?assert(1 =:= 2).
Execute the tests:
snowch@tp:~/erlangscratch$ rebar co eu ==> erlangscratch (compile) ==> erlangscratch (eunit)
The tests weren't executed, but it also seems that the code isn't compiling.
Here are the contents of my folder:
snowch@tp:~/erlangscratch$ tree . . ├── src │ └── erlangscratch.erl └── test └── erlangscratch_tests.erl 2 directories, 2 files
Question: What step(s) have I missed out?
UPDATE:
As per the accepted answer,
basic_test_
function needed to be renamed and the 'src/erlangscratch.app.src' was missing so I created it with the following contents:{application, erlangscratch, [ {description, "An Erlang erlangscratch library"}, {vsn, "1"}, {modules, [ erlangscratch ]}, {registered, []}, {applications, [ kernel, stdlib ]}, {env, []} ]}.
解决方案You are mixing tests with test generators.
In short the second one should return fun's or lists of fun's. You can distinguish both by
_
at the end of your tests names, and_
and the beginning of your macros.Simple solution would be using either
basic_test() -> ?assert(1 =:= 2).
or
basic_test_() -> ?_assert(1 =:= 2).
depending on your needs, and what you understand better.
EDIT after sharing folder structure
It seems rebar is not recognizing your project as an OTP application. You might be just missing simple
.app.src
file. Something like:{application, myapp, [ {description, ""}, {vsn, "1"}, {registered, []}, {applications, [ kernel, stdlib ]}, {env, []} ]}.
And since rebar is capable of generating one for you, you either just call
rebar create-app
or extend one of existing templates.这篇关于如何使用钢筋来创建一个具有eunit测试的erlang模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!