37 lines
3.5 KiB
HTML
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 "for (foo 3)," (1,2) (foo 3))
|
|
test2 = TestCase (do (x,y) <- partA 3
|
|
assertEqual "for the first result of partA," 5 x
|
|
b <- partB y
|
|
assertBool ("(partB " ++ show y ++ ") failed") b)
|
|
</pre><p>Name the test cases and group them together:</p><pre> tests = TestList [TestLabel "test1" test1, TestLabel "test2" 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
|
|
### 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 [ "test1" ~: "(foo 3)" ~: (1,2) ~=? (foo 3),
|
|
"test2" ~: do (x, y) <- partA 3
|
|
assertEqual "for the first result of partA," 5 x
|
|
partB y @? "(partB " ++ show y ++ ") failed" ]
|
|
</pre><p>Assuming the same test failures as before, you would see:</p><pre> > runTestTT tests
|
|
### 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.16.0</p></div></body></html> |