1 / 10

Testing in Erlang

Testing in Erlang. Different testing tools. EUnit (standard lightweight xUnit solution for Erlang) Common Test (OTP based distributed testing tool) Qucik Check (property based testing tool). A simple problem (deleting from a list). 4>lists:delete(2,[1,2,3]). [1,3]

fionan
Download Presentation

Testing in Erlang

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Testing in Erlang

  2. Different testing tools • EUnit (standard lightweight xUnit solution for Erlang) • Common Test (OTP based distributed testing tool) • Qucik Check (property based testing tool)

  3. A simple problem (deleting from a list) • 4>lists:delete(2,[1,2,3]). • [1,3] • 5>lists:delete(4,[1,2,3]). • [1,2,3] • We should write a test for delete like this: • delete_present_test()-> • lists:delete(2,[1,2,3])==[1,3]. • delete_absent_test()-> • lists:delete(4,[1,2,3])==[1,2,3].

  4. Problems with xUnit style solution • Lots of work to create “good” tests and various test cases • The code as good as your tests • Can’t create and validate with formal specification

  5. What other solution is possible • We’d like to generalise our tests • We’d like to generate or run different cases automatically • We’d like to avoid the “human failure” from the system (if it is even possible) • We’d like to write something like this: • prop_delete(I,L)-> • notlists:member(I,lists:delete(I,L)).

  6. QuickCheck is the solution • With QuickCheck we can test our property automatically in many cases without the effort of specifying each case manually • So we can write QuickCheck property like this: • prop_delete()-> • ?FORALL({I,L},{int(),list(int())}, • notlists:member(I,lists:delete(I,L))).

  7. Test data generators • Instead of the logically meaning QuickCheck interprets the expression as a data generator • int() is a generator of random integers • list(int()) is a generator of random lists containing integers • {int(), list(int)} produces pairs of integer and a list of integers • ?FORALL binds {I,L} to the pattern {int(), list(int)}

  8. Running the test • eqc:quickcheck(examples:prop_delete()). • Works fine! • eqc:quickcheck(eqc:numtests(1000,examples:prop_delete())). • Fails… • Diagnosis and shrinking

  9. Conditional properties • ?IMPLIES • prop_delete()-> • ?FORALL({I,L},{int(),list(int())}, • ?IMPLIES(no_duplicates(L), • notlists:member(I,lists:delete(I,L)))). • no_duplicates(L)->lists:usort(L)==lists:sort(L).

  10. Custom generators • We can create our own generators • ulist(Elem)-> • ?LET(L,list(Elem), • lists:usort(L)).

More Related