HUnit is a unit testing framework for Haskell, similar to JUnit for Java.
Questions tagged [hunit]
58 questions
2
votes
1 answer
Pattern for generic unit test of type class instance implementations in Haskell
I was wondering if there was a known pattern for writing generic unit test code whose purpose it is to check (as a black box) the various instance (implementation of) a type class. For example:
import Test.HUnit
class M a where
foo :: a ->…

Sven Williamson
- 1,094
- 1
- 10
- 19
2
votes
1 answer
PutText in haskell HUnit
I have recently been using the HUnit testing framework to run unit
tests in haskell.
I came across this function PutText and runTestText which takes
PutText st as its first argument.
However i am not sure how to use this and would like some help in…

Yusuf
- 491
- 2
- 8
2
votes
1 answer
"Could not find module ‘Test.HUnit’" Error when executing Haskell's unittest (HUnit) in CodeRunner
I have simple unit test code for Haskell's HUnit. I use Mac OS X 10.10, and I installed HUnit with cabal install hunit.
module TestSafePrelude where
import SafePrelude( safeHead )
import Test.HUnit
testSafeHeadForEmptyList ::…

prosseek
- 182,215
- 215
- 566
- 871
2
votes
1 answer
Random Word8 duplicate instance declaration during cabal testpack installation
What does the following error message mean when cabal install testpack-2.1.1 has failed:
... Everything above this succeeded with no problems.
[22 of 22] Compiling Control.Monad.Cont ( Control/Monad/Cont.hs, dist/build/Control/Monad/Cont.o…

ely
- 74,674
- 34
- 147
- 228
1
vote
1 answer
Mock Database connections in haskell
I am trying to write some simple code in haskell where there is a function performs a simple database query. In order to unit test Iam using HUnit but not sure how I can mock the database connection and query response.

vijaicv
- 535
- 5
- 9
1
vote
1 answer
Haskell: Multiple Assertions in Unit Testing?
I looked up a similar topic and found this snippet of code from here: https://stackoverflow.com/a/21419654/14386048
To quote:
Let's assume that we have module SafePrelude.hs:
module SafePrelude where
safeHead :: [a] -> Maybe a
safeHead [] =…

lattejiu
- 119
- 8
1
vote
0 answers
Haskell Cabal HUnit
I have a project in school where it is required to use
import Test.HUnit
I have installed it I cabal using
cabal install HUnit --lib
but when I try to run our code we get this error message:
Huffman.hs:8:1: error:
Ambiguous module name…

kesha
- 11
- 1
1
vote
1 answer
Haskell HUnit Function Testing
I'm trying to set up a series of tests for a simple tic tac toe program I've written in Haskell and I'm unable to get past my first test due to a strange error being thrown reading:
Tests.hs:11:61: error:
* Couldn't match expected type `Int'…

TheRojBlakeV2
- 23
- 3
1
vote
1 answer
Why won't my test file import my datastructure? Haskell
I am currently writing unit tests for my (very simple) blackjack game and my testfile (Tests.hs) does not seem to import my datastructures that I have declared in the file I am doing unit tests for (HelpFunctions.hs). I can acces the…

Meltdown
- 99
- 4
1
vote
1 answer
HUnit does not allow to compile test cases if `Nothing == Nothing` condition is present in the test
I have encountered a weird HUnit behavior. It does not allow to compile test cases if Nothing == Nothing condition is present in the test. Here is my code that reproduces this behavior:
module TestTest where
import Control.Exception
import…

altern
- 5,829
- 5
- 44
- 72
1
vote
1 answer
Cabal error: At least the following dependencies are missing:
I am trying to create a test suite for my Haskell/Cabal package using HUnit, and am getting the following error when I run cabal test:
matthew@matthew-Gnawty:~/backup/projects/apollo$ cabal test
Re-configuring with test suites enabled. If this…

mherzl
- 5,624
- 6
- 34
- 75
1
vote
1 answer
Cabal and HUnit interaction
I am trying to get a simple unit test to work, written in HUnit.
The module I have put the test in is named "MyTests".
module MyTests where
import qualified Test.HUnit as H
gamma = H.TestCase (H.assertEqual "foo" 1 1)
-- Run the tests from the…

Christophe De Troyer
- 2,852
- 3
- 30
- 47
1
vote
1 answer
Dependency issues running "cabal test" for Haskell
I'm running my first "cabal test" for Haskell, but I get the error:
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring sample-0.1.0.0...
cabal: At…

Suavocado
- 949
- 12
- 27
1
vote
1 answer
How to resolve type ambiguity in this unit test
I can't figure out how to annotate the mylast3 test properly:
import Test.HUnit
mylast :: [a] -> Maybe a
mylast [] = Nothing
mylast [x] = Just x
mylast (_:xs) = mylast xs
testsMyLast =
[TestCase $ assertEqual "mylast1" (Just 1) $ mylast [1],
…

Denis Gorodetskiy
- 2,884
- 3
- 21
- 23
1
vote
1 answer
Comparison for Text.XML.Light.Element in test
I am trying to write a simple hunit-test to verify how a Text.XML.Light.Element is created from a function.
The function is:
createElement :: String -> String -> XML.Element
createElement tg txt =
blank_element{ elName = qualName tg
,…

Randomize
- 8,651
- 18
- 78
- 133