[Haskell-beginners] Where do you put your tests?
Brent Yorgey
byorgey at seas.upenn.edu
Sat Jul 21 20:12:21 CEST 2012
On Sat, Jul 21, 2012 at 08:04:35PM +0200, Magnus Therning wrote:
> On Sat, Jul 21, 2012 at 7:50 PM, Michael Orlitzky <michael at orlitzky.com> wrote:
> > On 07/19/2012 09:27 AM, damodar kulkarni wrote:
> >>
> >> Good because library dependencies are reduced, but bad because tests
> >> are somewhat "disconnected" from the functions they are testing.
> >>
> >>
> >> AFAIK, it's a good engineering practice to separate the tests from the
> >> code they are supposed to test. Code management issues will be there,
> >> but those can be taken care with the help of cabal like tool.
> >> That way, a person who wants to test will use the test-files and the one
> >> who doesn't want will be spared the trouble of separating tests from the
> >> intended function code.
> >>
> >
> > This is the solution I'd prefer, but I quickly ran into a problem: if I
> > want to test internal (non-exported) functions, the tests need to be in
> > the same module as the code.
> >
> > Is there a way around this?
> >
> > (For now, I just put the code in the same file and depend on the test libs.)
>
> A common issue. I, and some others I've seen, have a FooInternal
> module exporting *everything* for the tests, and a Foo module
> exporting only the public API.
I do this too. (For an example, see
http://hackage.haskell.org/package/split ). It has another benefit
beyond testing: I tend to export both modules from the package, and
make it clear that beginning users should start by looking at the
module with the public API; but for power users who want more control
or access and don't mind the possibility of shooting themselves in the
foot, the "export everything" module is also available.
-Brent
More information about the Beginners
mailing list