From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA28299; Fri, 21 Feb 2003 09:29:41 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA28454 for ; Fri, 21 Feb 2003 09:29:40 +0100 (MET) Received: from smtp6.wanadoo.nl (smtp6.wanadoo.nl [194.134.35.177]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h1L8TeT24858 for ; Fri, 21 Feb 2003 09:29:40 +0100 (MET) Received: from wanadoo.nl (unknown [62.234.208.99]) by smtp6.wanadoo.nl (Postfix) with ESMTP id 7C82B72813; Fri, 21 Feb 2003 09:29:38 +0100 (CET) Message-ID: <3E55E247.7070805@wanadoo.nl> Date: Fri, 21 Feb 2003 09:24:39 +0100 From: Maas-Maarten Zeeman User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1 X-Accept-Language: en MIME-Version: 1.0 To: mgushee@havenrock.com Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] OUnit usage References: <3E5541E5.15804.8F7F3E@localhost> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, >If I could see 1 or 2 simple but realistic examples, I think that would clear up the >mystery. > > Indeed I admid, the documentation is currently not very helpful, but I did not want to wait to release the software until it was. Maybe this is a good trigger to start working on it, but don't hold your breath until it is finished. I'm currently very busy with other (not ocaml related) stuff. If you are brave enough however, you could take a look test code in the OUnit distribution itself. The OcamlExpat distribution also contains some real live test examples, which might already be helpful. To clarify things (a bit) more: The basic idea of a TestCase is that it contains a function, which is executed at test time. When the function executes without any exceptions it was successful, when the function raises Failure, it is flagged as being failed, and when some other exception is raised it has errored. Now a small (realistic?) example open OUnit let empty_list = [] let list_a = [1;2;3] let test_list_length _ = assert_equal 0 (List.length empty_list); assert_equal 3 (List.length list_a) (* etc, etc *) let test_list_append _ = let list_b = List.append empty_list [1;2;3] in assert_equal list_b list_a let suite = "OUnit Example" >::: ["test_list_length" >:: test_list_length; "test_list_append" >:: test_list_append] let _ = let verbose = ref false in let set_verbose _ = verbose := true in Arg.parse [("-verbose", Arg.Unit set_verbose, "Run the test in verbose mode.");] (fun x -> raise (Arg.Bad ("Bad argument : " ^ x))) ("usage: " ^ Sys.argv.(0) ^ " [-verbose]"); if not (was_successful (run_test_tt ~verbose:!verbose suite)) then exit 1 Which can be compiled as follows: $ ocamlc -o example unix.cma oUnit.cmo example.ml And run like this: $ ./example -verbose OUnit Example:0:test_list_length ... ok OUnit Example:1:test_list_append ... ok Ran: 2 tests in: 0.00 Seconds OK When something is wrong you will see the following: $ ./example -verbose OUnit Example:0:test_list_length ... FAIL OUnit Example:1:test_list_append ... ok ====================================================================== FAIL: OUnit Example:0:test_list_length OUnit: not equal ---------------------------------------------------------------------- Ran: 2 tests in: 0.00 Seconds FAILED: Cases: 2 Tried: 2 Errors: 0 Failures: 1 I hope this was helpful. If you are eager to learn more, I would like to refer you to the original unit test article made by Kent Beck, http://www.xprogramming.com/testfram.htm. The article describes the unit test philosophy, and a smalltalk implementation of a unit test framework. Much of it holds for OUnit. Regards, Maas ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners