Reducing boilerplate in HUnit tests

I am new to HUnit and was surprised to see that it is necessary to list all the test functions to be able to run them all in a single command, e.g.:

tests = TestList [TestLabel "t0" t0,
                  TestLabel "t1" t1,
                  TestLabel "t2" t2,
                  TestLabel "t3" t3,
                  TestLabel "t4" t4,
                  TestLabel "t5" t5,
                  TestLabel "t6" t6
                 ]

where each of the test functions has its own boilerplate, along these lines:
t0 = TestCase ( assertEqual "test name" expected-value expression )

In other languages, such as Go and Rust, there is much less boilerplate/ceremony.

Is there any support for scanning a module for expressions of type Test and running all of them?

Apologies if Iā€™m thinking about this in the wrong way - feel free to correct my understanding if appropriate.

I think the best option is to use the tasty test framework with tasty-discover. This supports discovering hunit tests.

See GitHub - haskell-works/tasty-discover.

1 Like