Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 9cb8b39b0a31c736c18ed9124753add2 > files > 27

ghc-HUnit-devel-1.2.2.1-4.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--Rendered using the Haskell Html Library v0.2-->
<HTML
><HEAD
><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"
><TITLE
>Test.HUnit</TITLE
><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css"
><SCRIPT SRC="haddock-util.js" TYPE="text/javascript"
></SCRIPT
><SCRIPT TYPE="text/javascript"
>window.onload = function () {setSynopsis("mini_Test-HUnit.html")};</SCRIPT
></HEAD
><BODY
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="topbar"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD
><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" "
></TD
><TD CLASS="title"
>HUnit-1.2.2.1: A unit testing framework for Haskell</TD
><TD CLASS="topbut"
><A HREF="src/Test-HUnit.html"
>Source code</A
></TD
><TD CLASS="topbut"
><A HREF="index.html"
>Contents</A
></TD
><TD CLASS="topbut"
><A HREF="doc-index.html"
>Index</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="modulebar"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD
><FONT SIZE="6"
>Test.HUnit</FONT
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Description</TD
></TR
><TR
><TD CLASS="doc"
><P
>HUnit is a unit testing framework for Haskell, inspired by the JUnit tool 
 for Java. This guide describes how to use HUnit, assuming you are familiar 
 with Haskell, though not necessarily with JUnit.
</P
><P
>In the Haskell module where your tests will reside, import module 
 <TT
>Test.HUnit</TT
>:
</P
><PRE
>
    import Test.HUnit
</PRE
><P
>Define test cases as appropriate:
</P
><PRE
>
    test1 = TestCase (assertEqual <A HREF="for (foo 3),.html"
>for (foo 3),</A
> (1,2) (foo 3))
    test2 = TestCase (do (x,y) &lt;- partA 3
                         assertEqual <A HREF="for the first result of partA,.html"
>for the first result of partA,</A
> 5 x
                         b &lt;- partB y
                         assertBool (<A HREF="(partB .html"
>(partB </A
> ++ show y ++ <A HREF=") failed.html"
>) failed</A
>) b)
</PRE
><P
>Name the test cases and group them together:
</P
><PRE
>
    tests = TestList [TestLabel <A HREF="test1.html"
>test1</A
> test1, TestLabel <A HREF="test2.html"
>test2</A
> test2]
</PRE
><P
>Run the tests as a group. At a Haskell interpreter prompt, apply the function
 <TT
>runTestTT</TT
> to the collected tests. (The <EM
>TT</EM
> suggests <EM
>T</EM
>ext orientation 
 with output to the <EM
>T</EM
>erminal.)
</P
><PRE
>
    &gt; runTestTT tests
    Cases: 2  Tried: 2  Errors: 0  Failures: 0
    &gt;
</PRE
><P
>If the tests are proving their worth, you might see:
</P
><PRE
>
    &gt; runTestTT tests
    <A NAME="#"
><A NAME="%23"
></A
></A
> Failure in: 0:test1
    for (foo 3),
    expected: (1,2)
     but got: (1,3)
    Cases: 2  Tried: 2  Errors: 0  Failures: 1
    &gt;
</PRE
><P
>You can specify tests even more succinctly using operators and overloaded 
 functions that HUnit provides:
</P
><PRE
>
    tests = test [ <A HREF="test1.html"
>test1</A
> ~: <A HREF="(foo 3).html"
>(foo 3)</A
> ~: (1,2) ~=? (foo 3),
                   <A HREF="test2.html"
>test2</A
> ~: do (x, y) &lt;- partA 3
                                 assertEqual <A HREF="for the first result of partA,.html"
>for the first result of partA,</A
> 5 x
                                 partB y @? <A HREF="(partB .html"
>(partB </A
> ++ show y ++ <A HREF=") failed.html"
>) failed</A
> ]
</PRE
><P
>Assuming the same test failures as before, you would see:
</P
><PRE
>
    &gt; runTestTT tests
    <A NAME="#"
><A NAME="%23"
></A
></A
> Failure in: 0:test1:(foo 3)
    expected: (1,2)
     but got: (1,3)
    Cases: 2  Tried: 2  Errors: 0  Failures: 1
    &gt;
</PRE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Documentation</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
>module <A HREF="Test-HUnit-Base.html"
>Test.HUnit.Base</A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="decl"
>module <A HREF="Test-HUnit-Text.html"
>Test.HUnit.Text</A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="botbar"
>Produced by <A HREF="http://www.haskell.org/haddock/"
>Haddock</A
> version 2.6.1</TD
></TR
></TABLE
></BODY
></HTML
>