title: Haskell: Multiple Assertions in Unit Testing?
body: <p>I looked up a similar topic and found this snippet of code from here: <a href="https://stackoverflow.com/a/21419654/14386048">https://stackoverflow.com/a/21419654/14386048</a></p>
  <p>To quote:<br>
  Let's assume that we have module <code>SafePrelude.hs</code>:</p>
  <pre><code>module SafePrelude where
  
  safeHead :: [a] -&gt; Maybe a
  safeHead []    = Nothing
  safeHead (x:_) = Just x
  </code></pre>
  <p>we can put tests into <code>TestSafePrelude.hs</code> as follows:</p>
  <pre><code>module TestSafePrelude where
  
  import Test.HUnit
  import SafePrelude
  
  testSafeHeadForEmptyList :: Test
  testSafeHeadForEmptyList = 
      TestCase $ assertEqual &quot;Should return Nothing for empty list&quot;
                             Nothing (safeHead ([]::[Int]))
  
  testSafeHeadForNonEmptyList :: Test
  testSafeHeadForNonEmptyList =
      TestCase $ assertEqual &quot;Should return (Just head) for non empty list&quot; (Just 1)
                 (safeHead ([1]::[Int]))
  
  main :: IO Counts
  main = runTestTT $ TestList [testSafeHeadForEmptyList, testSafeHeadForNonEmptyList]
  </code></pre>
  <p>-- End Quote --<br>
  Is it possible to have multiple assertions within, let's say, <code>testSafeHeadForEmptyList</code>? I'm trying to categorize my test samples of similar cases, but just different variations. I want to avoid something like this below (assume each assert equal has a different variation, but all should return nothing, for example):</p>
  <pre><code>testSafeHeadForEmptyList :: Test
  testSafeHeadForEmptyList = 
      TestCase $ assertEqual &quot;Should return Nothing for empty list&quot;
                             Nothing (safeHead ([]::[Int]))
  testSafeHeadForEmptyList2 :: Test
  testSafeHeadForEmptyList2 = 
      TestCase $ assertEqual &quot;Should return Nothing for empty list&quot;
                             Nothing (safeHead ([]::[Int]))
  ...
  testSafeHeadForEmptyList99 :: Test
  testSafeHeadForEmptyList99 = 
      TestCase $ assertEqual &quot;Should return Nothing for empty list&quot;
                             Nothing (safeHead ([]::[Int]))
  </code></pre>
  <p>Is this possible in Haskell?</p>