HUnit is a unit testing framework for Haskell, similar to JUnit for Java.
Questions tagged [hunit]
58 questions
36
votes
2 answers
What is the Haskell syntax to import modules in subdirectories?
What is Haskell's syntax for importing modules in another directory?
I'm getting started with Haskell and want to practice writing simple functions TDD style with HUnit. I'm having trouble figuring out how to structure my files, though. The example…

Josh Earl
- 18,151
- 15
- 62
- 91
21
votes
1 answer
Current state of integrating unit tests with Haskell's Cabal?
When i google for how to integrate unit tests with cabal files, i either find
http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program which does not seem to describe the integration of HUnit/QuickCheck with the Cabal file
or i see…

LennyStackOverflow
- 2,228
- 1
- 19
- 22
16
votes
2 answers
How to use HUnit and Cabal to do Automated Testing?
I've been fighting with Cabal for a good portion of a day trying to make its automated testing features work with HUnit. I've read the documentation here and here, and I have my Test-Suite section set up like it shows, but whenever I try and build…

Dwilson
- 1,239
- 9
- 18
12
votes
1 answer
Creating a Full Haskell Stack with Tests
I'm new to Haskell and I'm trying to structure a program under test. I have decided to use HUnit and Cabal.
From what I have seen a well strucutred project looks the following:
src/
AppName/
Appname.hs
testsuite/
tests/
AppName/
…

GTDev
- 5,488
- 9
- 49
- 84
11
votes
2 answers
HUnit/QuickCheck with Continuous Integration
Are there any extensions to HUnit or QuickCheck that allow a continuous integration system like Bamboo to do detailed reporting of test results?
So far, my best idea is to simply trigger the tests as part of a build script, and rely on the tests to…

acfoltzer
- 5,588
- 31
- 48
11
votes
1 answer
Why does my HUnit test suite fail but pass successfully in Cabal?
If I have test/Test.hs with
module Main where
import Test.HUnit
test1 :: Test
test1 = TestCase $ assertEqual "Should be one" 1 5
test2 :: Test
test2 = TestCase $ assertEqual "Shold both be zero" 0 0
main :: IO Counts
main = runTestTT $ TestList…

orome
- 45,163
- 57
- 202
- 418
9
votes
2 answers
How do I test for an error in Haskell?
I want to be able to make sure a function will throw an error when it receives and invalid value. For example, let says I have a function pos that only returns a positive number:
pos :: Int -> Int
pos x
| x >= 0 = x
| otherwise = error…

Joe Hillenbrand
- 845
- 9
- 26
8
votes
2 answers
get function name inside it
I have a bunch of functions like: method1, method2, method3. For all of them there are HUnit test functions like: testMethod1, testMethod2, testMethod3.
testMethod1 = TestCase $
assertEqual "testmethod1" ...
testMethod2 = TestCase $
assertEqual…

ДМИТРИЙ МАЛИКОВ
- 21,474
- 11
- 78
- 131
7
votes
1 answer
Is it possible to use HUnit with test-framework in a monad other than IO?
I currently have the following test code:
testUpdate :: Test
testUpdate = testCase "update does change artist" $ do
(created, Just revised, parents) <- mbTest $ do
Just editor <- fmap entityRef <$> findEditorByName "acid2"
created <-…

ocharles
- 6,172
- 2
- 35
- 46
6
votes
1 answer
Is it possible to assert an error case in HUnit?
If I have a function which results in an error for a certain input, is it possible to write a test verifying the error occurs for that input?
I do not find this "assert error" functionality available in HUnit. Is it available in HUnit or perhaps in…

mherzl
- 5,624
- 6
- 34
- 75
6
votes
1 answer
Stack with Travis CI
I have recently been trying to use travis CI with stack and i have
been running in to some issues.
my .travis.yml file is located in my repo which is here:
(I used the guide on the stack website)
A snapshot of my config file is as follows:
sudo:…

Yusuf
- 491
- 2
- 8
6
votes
1 answer
Dynamically generate Tasty `TestTree` from the file system
I have written a file parser using the Parsec library. I would like to write a high-level unit test using the Tasty testing framework to ensure that the parser correctly parses some given files.
I have three well formatted files in the following…

recursion.ninja
- 5,377
- 7
- 46
- 78
6
votes
1 answer
Mocking IO Actions: getArgs and putStrLn
I'm trying to test a small function (or rather, IO Action) that takes a command line argument and outputs it to the screen. My original (untestable) function is:
-- In Library.hs
module Library where
import System.Environment (getArgs)
run :: IO…

Michal Charemza
- 25,940
- 14
- 98
- 165
6
votes
1 answer
Can't find module Test.HUnit
I am trying to make some unit tests in Haskell and this is basically what I have done in my code:
module Test where
import Test.HUnit
test = TestList [TestLabel "running all the tests!"
$ TestList [
. . . . .
]]
run = runTestTT tests
When I…

sokras
- 629
- 1
- 8
- 19
5
votes
1 answer
Interaction between optimizations and testing for error calls
I have a function in a module that looks something like this:
module MyLibrary (throwIfNegative) where
throwIfNegative :: Integral i => i -> String
throwIfNegative n | n < 0 = error "negative"
| otherwise = "no worries"
I could…

hammar
- 138,522
- 17
- 304
- 385