<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Test.HUnit</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_Test-HUnit.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Test-HUnit.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">HUnit-1.2.2.3: A unit testing framework for Haskell</p></div><div id="content"><div id="module-header"><p class="caption">Test.HUnit</p></div><div id="description"><p class="caption">Description</p><div 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 <code>Test.HUnit</code>: </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) <- partA 3 assertEqual <a href="for the first result of partA,.html">for the first result of partA,</a> 5 x b <- 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 <code>runTestTT</code> to the collected tests. (The <em>TT</em> suggests <em>T</em>ext orientation with output to the <em>T</em>erminal.) </p><pre> > runTestTT tests Cases: 2 Tried: 2 Errors: 0 Failures: 0 > </pre><p>If the tests are proving their worth, you might see: </p><pre> > runTestTT tests <a name=""></a># Failure in: 0:test1 for (foo 3), expected: (1,2) but got: (1,3) Cases: 2 Tried: 2 Errors: 0 Failures: 1 > </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) <- 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> > runTestTT tests <a name=""></a># Failure in: 0:test1:(foo 3) expected: (1,2) but got: (1,3) Cases: 2 Tried: 2 Errors: 0 Failures: 1 > </pre></div></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src">module <a href="Test-HUnit-Base.html">Test.HUnit.Base</a></p></div><div class="top"><p class="src">module <a href="Test-HUnit-Text.html">Test.HUnit.Text</a></p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>