1

I have written a Haskell module that contains functions that operate on some state. Let's say that the code looks like this (the actual functions may return an actual result instead of (), but this is irrelevant to the question):

data StateContext = StateContext {
  -- some records
}

handleEventA :: EventA -> State StateContext ()
handleEventB :: EventB -> State StateContext ()
handleEventC :: EventC -> State StateContext ()

As you can imagine the behavior of each function depends on the current state. For example handleEventA >> handleEventB will not produce the same result as handleEventB >> handleEventA. So I have several HUnit tests that verify the behavior of each function at several states.

But now I would like to write more tests, that exercise all functions at all possible states (the number of states is finite). Writing them with HUnit would be quite labor-itensive, so I thought that using QuickCheck might be helpful in that case (I have only used it before for trivial functions).

But I cannot see which properties should I test, or what kind of data should the test generate. I suspect that the test should generate random sequence of events (e.g. handleEventB >> handleEventC >> handleEventA etc), but I cannot see what properties should be satisfied.

Boulougou
  • 46
  • 1
  • 4
  • The properties you want to test are likely specific to your program. Perhaps you can extrapolate from your HUnit tests to find some more general properties that should hold. – ase Feb 04 '17 at 21:45
  • Yeah, it'd help to know more about your domain, and to have a running program, but some suggestions: is there some sequence of events that must occur to reach some state? For example, on a web site, there might be a login and password before a "view the sensitive info" page. Or, in a vending machine, all events must end in one of: returned change, or vended drink. Or, if you're modelling an office process, the event "cut a check" must the proceeded by a "issued purchase order", ..., "received invoice", ..... – ja. Feb 08 '17 at 05:05
  • Also, since the number of states is finite, have a look at [Smallcheck](https://www.cs.york.ac.uk/fp/smallcheck/smallcheck.pdf). – ja. Feb 10 '17 at 21:46

0 Answers0