I'm writing a Haskell JSON API, and I'd like to write some tests. The thing is really IO heavy, so I think it makes the most sense to write some functional tests: (Add a Foo, see if /foos/ returns it), etc.
I've read about QuickCheck of course, but it seems to focus on testing pure code.
How should I write/run functional tests that need to test an API? If it matters, I'm using Scotty/WAI. Although an example would be great, a good couple links and some advice would be fine.
I've never used it, but QuickCheck actually does support testing monadic code. Look at Testing IO actions with Monadic QuickCheck for more information. If your api has some invariants that are easy to express, this is probably a good way to test it. (In my experience with pure code, QuickCheck covers more corner cases than I can think of, which makes it very useful.)
I have a half-baked(yet almost done) blog entry to explain how to test wai application with hspec. Hope it helps!
https://github.com/fujimura/wai-hspec-example/blob/master/testing-wai-app-with-hspec.md https://github.com/fujimura/wai-hspec-example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With