[erlang-questions] Testing api with jsongen and quickcheck

Mark Bruch mark.h.bruch@REDACTED
Tue Aug 25 00:41:29 CEST 2015


On Fri, Aug 21, 2015 at 7:58 PM, Garret Smith <garret.smith@REDACTED> wrote:
> On Fri, Aug 21, 2015 at 10:45 AM, Mark Bruch <mark.h.bruch@REDACTED> wrote:
>> On Fri, Aug 21, 2015 at 7:33 PM, Garret Smith <garret.smith@REDACTED> wrote:
>>> On Fri, Aug 21, 2015 at 10:24 AM, Kenneth Lakin <kennethlakin@REDACTED> wrote:
>>>> On 08/21/2015 09:27 AM, Mark Bruch wrote:
>>>>> Unfortunately [jsongen] doesn't compile on any of
>>>>> my machines.
>>>>
>>>> It fails to compile with rebar3 on my machine, too.
>>>>
>>>> Stupid question, but do you have QuickCheck installed? The missing
>>>> include files that the build whines about seem to be related to QuickCheck.
>>>>
>>>> I found an eqcmini GitHub project, but that doesn't seem to provide
>>>> enough to get jsongen to build.
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>>
>>>
>>> Same problem with eqc.hrl here, once I replace 'make' with 'gmake'
>>> since I'm on FreeBSD.
>>>
>>> It's a different approach than jsongen, but I have a similar setup of
>>> a JSON API for an Erlang codebase.
>>> I'm using aeon* to convert JSON <=> Erlang records and sanitize the
>>> json input along the way.
>>> Since QuickCheck (and PropEr) can use the type info in Erlang records,
>>> you could:
>>>  1) Write Erlang records that correspond to your JSON
>>>  2) Use QC/PropEr to generate the Erlang records
>>>  3) Use aeon to convert the Erlang to JSON and call your API with it
>>>
>>> *aeon: https://github.com/garret-smith/aeon
>>>
>>> Yes, aeon is my own project.  Hopefully others can use it too.
>>>
>>> -Garret
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>> Yes, I've got the full version of QuickCheck installed.
>> For me it complains on: "src/js_links_machine.erl:none:
>> double_occurence of callouts in js_links_machine. Only grouped
>> functions or ungrouped functions, not both"
>>
>> Thanks for the pointers Garret, that sounds like a good and easy way
>> to do it. Will give your aeon a go :)
>
> I'd love to hear your experiences.  Hopefully doing it this way will
> give you better control over the testing since you're using Erlang
> types to generate the JSON.

Managed to create some property based tests for my API today and it
turned out awesome! :)

The only thing that could have made aeon a better fit is if was
possible to set fields to optional, so that missing fields in the
JSON-input doesn't give validation errors when converting to a record.
Would rather do validation with something like jesse [1] and allow
fields to be optional.

All in all I'm extremely pleased how it turned out, so thanks a lot
Garret and Kenneth!
Now off to fix the bugs that the tests found... ;)

[1] https://github.com/klarna/jesse



More information about the erlang-questions mailing list