Files
dotfiles/cabal/share/doc/x86_64-osx-ghc-7.10.1/HUnit-1.2.5.2/html/Test-HUnit.html
2015-04-05 17:47:08 +02:00

37 lines
3.5 KiB
HTML

<!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="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">HUnit-1.2.5.2: A unit testing framework for Haskell</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><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 &quot;for (foo 3),&quot; (1,2) (foo 3))
test2 = TestCase (do (x,y) &lt;- partA 3
assertEqual &quot;for the first result of partA,&quot; 5 x
b &lt;- partB y
assertBool (&quot;(partB &quot; ++ show y ++ &quot;) failed&quot;) b)
</pre><p>Name the test cases and group them together:</p><pre> tests = TestList [TestLabel &quot;test1&quot; test1, TestLabel &quot;test2&quot; 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> &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
### 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 [ &quot;test1&quot; ~: &quot;(foo 3)&quot; ~: (1,2) ~=? (foo 3),
&quot;test2&quot; ~: do (x, y) &lt;- partA 3
assertEqual &quot;for the first result of partA,&quot; 5 x
partB y @? &quot;(partB &quot; ++ show y ++ &quot;) failed&quot; ]
</pre><p>Assuming the same test failures as before, you would see:</p><pre> &gt; runTestTT tests
### Failure in: 0:test1:(foo 3)
expected: (1,2)
but got: (1,3)
Cases: 2 Tried: 2 Errors: 0 Failures: 1
&gt;
</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.16.0</p></div></body></html>