nponeccop
nponeccop

Reputation: 13677

Selective running of tests in HUnit

Test.HUnit provides a big red button to run a test:

runTestTT :: Test -> IO Counts

As there is a need to structure large test suites, Test is not a single test but is actually a labelled rose tree with Assertion in leaves:

data Test
  = TestCase Assertion | TestList [Test] | TestLabel String Test
        -- Defined in `Test.HUnit.Base'

It's not abstract so it's possible to process it. One particularly useful processing is extraction of subtrees by paths:

byPath = flip $ foldl f where
    f (TestList l) = (l !!)
    f (TestLabel _ t) = const t
    f t = const t     

So for example I can run a single subsuite runTestTT $ byPath [1] tests or a particular test runTestTT $ byPath [1,7,3] tests identified by test path instead of waiting for whole suite.

One disadvantage of the homegrown tool is that test paths are not preserved (shortened).

Is there such processing helper tool already on Hackage?

Upvotes: 2

Views: 131

Answers (1)

Joachim Breitner
Joachim Breitner

Reputation: 25782

The closest to your needs seem to be the libraries and programs that abstract over HUnit, Quickcheck and other tests, and have their own test name grouping and management infrastructure, e.g. test-framework. It provides you with a main function that takes command line arguments, including one that allows you to specify a test or test group to run (by globbing on the name).

Upvotes: 2

Related Questions