Yesod provides the yesod test
tool. A test is a value of type Spec
which can be executed by hspec
.
The scaffolding comes with a predefined spec in tests/HomeTest.hs
which is explicitly called in tests/main.hs
, the file that is apparently compiled and executed when you run yesod test
. I assume you are supposed to manually add all your specs to main.hs
as you create them, although perhaps there is a way to use hspec's automated test discovery.
This is great for regression testing, but what about test-driven development? What is the proper way to write a single test and then run it repeatedly during development? The help text for yesod test
suggests that there is no way to do this:
$ yesod test --help
Usage: yesod test
Build and run the integration tests
Running a spec file directly doesn't work (and I suppose you wouldn't expect it to, since it doesn't contain a main
definition):
$ runhaskell tests/HomeTest.hs
tests/HomeTest.hs:4:8:
Could not find module ‘TestImport’
Use -v to see a list of the files searched for.
$ cabal run tests/HomeTest.hs
cabal: Cannot build the executable 'myproject' because the component is marked as disabled in the .cabal file.
I'm not sure why my project's executable is disabled. Should I change that? Or should I create a temporary copy of main.hs
and comment out all the other tests? What's the cleanest solution?