Hacker News new | ask | show | jobs
by danuker 1477 days ago
How you would write tests in a real project?

I suppose it's not writing out the entire program and then writing the tests, as seems to be implied. That would mean a lot of manual testing.

Or is there a Haskell REPL where you can try out small pieces before saving them?

5 comments

When you create a project description for your project (for the package manager) you can define a library, executables and test suites.

In the test suite you write your tests against the library. You can do that at any stage, even before writing a line of library code.

But yes, Haskell also has a REPL that can be used to experiment with code.

In addition to the other good answers you've gotten, I would like to point out that Haskell has QuickCheck (https://hackage.haskell.org/package/QuickCheck) which, if I'm not mistaken, more or less pioneered property testing. Property testing libraries are available in many languages now but they never seem to be as capture the magic of QuickCheck. (There's also https://hackage.haskell.org/package/hedgehog which is sort of a "modern alternative" to QuickCheck but I still prefer the OG).
You have testing libraries in Haskell just like in every other languages. For example: https://hackage.haskell.org/package/tasty
Yes, there is GHCi, the Haskell interpreter and repl comes bundled with the compiler.

You can load your entire project in the repl and try your functions there.