HUnit is a unit testing framework for Haskell, similar to JUnit for Java.
Questions tagged [hunit]
58 questions
1
vote
1 answer
How to test my own data Types using HUnit in Haskell?
Part of Queue.hs:
module Queue ( Queue, emptyQueue, isEmptyQueue, enQueue, deQueue ) where
data Queue a = EmptyQueue | Single a | Q a ( Queue a ) a deriving (Show, Eq)
emptyQueue :: Queue a
emptyQueue = EmptyQueue
enQueue :: a -> Queue a -> Queue…

liubiantao
- 1,311
- 2
- 12
- 13
1
vote
0 answers
HUnit tests within cabal sandbox
After having some trouble I managed to configure my Cabal project so that it runs a simple stub test True @=? True. It works still if I substitute one value with a constant from tested package. However when I try to create an instance of a custom…

Sventimir
- 1,996
- 3
- 14
- 25
1
vote
1 answer
How do I make HUnit print linebreaks in assertion failures?
Some of my HUnit tests compare fairly large structures with assertEqual. It's hard to spot errors in these since HUnit prints the strings on one line. What I'd like to do is use Text.Groom to pretty print these structures, but if I pass a string to…

Adam Bergmark
- 7,316
- 3
- 20
- 23
0
votes
1 answer
Unit testing of internal functions of a module while avoiding dependencies to test framework and HUnit
Background
Using stack, and its preset file Spec.hs, as far as I know you need to import the following test framework modules in order to execute a proper test:
import qualified Test.Framework as TF
import qualified Test.Framework.Providers.HUnit as…

Jörg Brüggmann
- 603
- 7
- 19
0
votes
1 answer
Tasty HUnit test against Either
I am fairly new to Haskell, and I was wondering if there is a way to test a pattern match, as in erlang.
An example is a function that returns an Either a b, Can I match against Left b, whilst ignoring b itself?
In my case, I have Either String…

kumalka
- 33
- 4
0
votes
0 answers
How to unit test smart constructor that throw when construction is impossible?
I am implementing "smart" constructor performing runtime checking as described here
https://wiki.haskell.org/Smart_constructors#Smart.28er.29_constructors
My first question is : how to unit test that invalid argument throws ?
Here is what I have…

sandwood
- 2,038
- 20
- 38
0
votes
1 answer
how to test import Control.Monad.Except with Hunit?
How can I test Control.Monad.Except (both guard results) a function like:
foo :: Double -> Double -> Except String Double
foo x y
| x < -10.0 = throwError "Invalid parameter"
| otherwise = pure $ x + y
using hunit?

Randomize
- 8,651
- 18
- 78
- 133
0
votes
2 answers
Unit testing for exceptions
Can I write a test case with Test.HUnit that checks whether a call throws an exception?
I only care whether it throws any error, regardless of what message it prints.

bantmen
- 748
- 6
- 17
0
votes
1 answer
Run HUnit without output
I have a Test:
test1 = TestCase (assertEqual "Bla" 2 (add1 1))
And want to run it in another Haskell programm without automatic I/O output which
runTestTT test1
would create. I tried
runTestText (putTextToHandle stderr False) test1
but this…

Arne
- 41
- 1
- 7
0
votes
1 answer
Running HUnit tests with Hspec
I want to run HUnit tests inside a spec:
module SHCSpec (spec)
where
import Test.Hspec
import Test.Hspec.Contrib.HUnit
import Test.HUnit
import SHC.Types
import SHC.Lix
spec :: Spec
spec = do
fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
…

rubik
- 8,814
- 9
- 58
- 88
0
votes
1 answer
Problems while integrating HUnit with Cabal
The command cabal install works fine, as does cabal configure --enable-tests. However, when I run cabal build -j it does not compile:
Building MoodleLatex-0.1.0.0...
Preprocessing executable 'moddlelat' for MoodleLatex-0.1.0.0...
Preprocessing test…

rubik
- 8,814
- 9
- 58
- 88
0
votes
1 answer
Propagating errors to cause HUnit tests to fail
I am writing an HUnit test for a function eval :: Wff -> Assignment -> Maybe Bool. Wff is a custom data type which is an abstract parse tree for a simplified subset of boolean expressions:
data Wff = Var Name
| Not Wff
| Or Wff…

Code-Apprentice
- 81,660
- 23
- 145
- 268
0
votes
1 answer
HUnit testing with file dependent tests
I have a lexer, and wish to test it against a set of known good test cases. These are held in a subdirectory ./test_src/ , and each has an extension testname.txt
What i'd like to do is get the paths to all relevant test cases:
getTestFiles :: IO…

OllieB
- 1,431
- 9
- 14