Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Functional Tests against a JSON API

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.

like image 300
Sean Clark Hess Avatar asked Feb 26 '12 00:02

Sean Clark Hess


2 Answers

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.)

like image 187
Tikhon Jelvis Avatar answered Oct 16 '22 05:10

Tikhon Jelvis


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

like image 31
fujimura Avatar answered Oct 16 '22 07:10

fujimura