[erlang-questions] how to run PropEr tests from Eunit?

Frédéric Trottier-Hébert fred.hebert@REDACTED
Fri Jun 24 00:54:36 CEST 2011


The simplest way I know to do them individually is with separate tests:

proper_test_() ->
    [?_assert(proper:quickcheck(prop_some_property())),
     ?_assert(proper:quickcheck(prop_some_property())),
     ...].

You can then create macros to do it for you of the form

-define(PROPTEST(A), ?_assert(proper:quickcheck(A()))).

and then call

proper_test_() ->
    [?PROPTEST(prop_something), ?PROPTEST(prop_something_else),
     ?PROPTEST(prop_other), ?PROPTEST(prop_last)].

or whatever you feel like.

If you want to run them all, make sure your module's properties all start with the prefix 'prop_'. Then you can do something like

proper_test() ->
    [] = proper:module(?MODULE).

which will find all the properties of the current module and run them for you. Also, don't forget to always include the proper include file first, because both PropEr and EUnit define a LET macro, but the PropEr one is the only one I've seen actively used.

--
Fred Hébert
http://www.erlang-solutions.com



On 2011-06-23, at 18:12 PM, Roman Shestakov wrote:

> hello,
> 
> I am trying to run PropEr tests from Eunit and I must admit, I can't figure out how to run them
> 
> 
> lets say I want to test the following three functions
> 
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date to atom
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_atom(date()) -> atom().
> date_to_atom({Year, Month, Day}) ->
>    list_to_atom(date_to_string({Year, Month, Day})).
> 
> %%--------------------------------------------------------------------
> %% @doc
> %% Convert Date to string
> %% @end
> %%--------------------------------------------------------------------
> -spec date_to_string(date()) -> string().
> date_to_string({Year, Month, Day}) ->
>    lists:flatten(io_lib:format("~4.10.0B~2.10.0B~2.10.0B", [Year, Month, Day])).
> 
> 
> %%--------------------------------------------------------------------
> %% @doc
> %% convert Date represented as atom into Erlang date format
> %% @end
> %%--------------------------------------------------------------------
> -spec atom_to_date(atom()) -> date().
> atom_to_date(Date) ->
>    Year = list_to_integer(lists:sublist(atom_to_list(Date),1,4)),
>    Month = list_to_integer(lists:sublist(atom_to_list(Date),5,2)),
>    Day = list_to_integer(lists:sublist(atom_to_list(Date),7,2)),
>    {Year, Month, Day}.
> 
> 
> 
> with the following property:
> 
> proper_time_to_atom() ->
>    ?FORALL(Date, date(),
>         begin
>         EncDate = ec_time_fns:atom_to_date(ec_time_fns:date_to_atom(Date)),
>         EncDate =:= Date
>         end).
>               
> running the following from erl works fine
> proper:quickcheck(ec_time_fns_tests:proper_time_to_atom()).
> 
> 
> but how do I make eunit to run these test?
> 
> 
> tried this , but it doesn't seem to work
> 
> time_to_atom_test_() ->
>    ?_test(proper:quickcheck(proper_time_to_atom())).
> 
> 
> any ideas?
> 
> Regards, Roman
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110623/8d3ce0eb/attachment.htm>


More information about the erlang-questions mailing list