yesod-test: integration testing for WAI/Yesod Applications

[ library, mit, testing, web, yesod ] [ Propose Tags ]

Behaviour Oriented integration Testing for Yesod Applications

[Skip to Readme]
Versions [faq] 0.1, 0.2.0,,,,,,, 0.2.1, 0.3.0,, 0.3.1,, 0.3.2, 0.3.3,,, 0.3.4, 0.3.5, 1.2.0, 1.2.1,,,,,, 1.2.2, 1.2.3,,, 1.2.4, 1.2.5, 1.2.6, 1.4.0,,,, 1.4.1,, 1.4.2,,, 1.4.3,, 1.4.4, 1.5,,,, 1.5.2, 1.5.3, 1.5.4,, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9,, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5,, 1.6.6,,, 1.6.7, 1.6.8, 1.6.9
Dependencies attoparsec (==0.10.*), base (>=4.3 && <5), blaze-html (>=0.4 && <0.6), blaze-markup (>=0.5.1 && <0.6), bytestring (>=0.9), case-insensitive (>=0.2), containers, hspec (>=1.1 && <1.3), html-conduit (>=0.0.1 && <0.1), http-types (==0.6.*), HUnit (==1.2.*), hxt (>=9.1.6), network (>=2.2 && <2.4), persistent (==0.9.*), text, transformers (>=0.2.2 && <0.4), wai (==1.2.*), wai-test (==1.2.*), xml-conduit (==0.7.*), xml-types (==0.3.*), xml2html (>= && <0.2) [details]
License MIT
Author Nubis <>
Maintainer Nubis <>, Michael Snoyman
Category Web, Yesod, Testing
Home page
Source repo head: git clone git://
Uploaded by MichaelSnoyman at Sat Jun 30 19:18:13 UTC 2012
Distributions Arch:1.6.9, Debian:1.6.5, FreeBSD:, LTSHaskell:, NixOS:1.6.9, Stackage:
Downloads 49123 total (2066 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]





use blaze-html 0.5 and blaze-markup 0.5


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for yesod-test-0.2.1

[back to package description]

TestWaiPersistent - Pragmatic integration tests for haskell web applications using WAI and Persistent

yesod-test is designed for testing web applications built using wai and persistent. It's main goal is to encourage integration and system testing of web applications by making everything /easy to test/. Your tests are like browser sessions that keep track of cookies and the last visited page. You can perform assertions on the content of HTML responses, using css selectors to explore the document more easily. You can also easily build requests using forms present in the current page. This is very useful for testing web applications built in yesod for example, were your forms may have field names generated by the framework or a randomly generated "_token" field. Your database is also directly available so you can use runDB to set up backend pre-conditions, or to assert that your session is having the desired effect. The testing facilities behind the scenes are HUnit and HSpec. This is the helloworld and kitchen sink. In this case for testing a yesod app.

  import Yesod
  import Yesod.Static
  import qualified MySite.Settings as Settings
  import MySite.Models

  main :: IO a
  main = do
    cfg <- (loadConfig Test) >>= either fail return
    st <-  static Settings.staticDir
    Settings.withConnectionPool (connStr cfg) $ \cnPool -> do
      -- ... Perhaps some code here to truncate your test database?
      app <- toWaiApp $ MyApp st cfg 
      runTests app cnPool $ mySuite

  mySuite = do
    describe "Basic navigation and assertions" $ do
      it "Gets a page that has a form, with auto generated fields and token" $ do
        get_ "url/of/page/with/form" -- Load a page
        statusIs 200 -- Assert the status was success

        bodyContains "Hello Person" -- Assert any part of the document contains some text.
        -- Perform a css queries and assertions.
        htmlCount "form .main" 1 -- It matches 1 element
        htmlAllContain "h1#mainTitle" "Sign Up Now!" -- All matches have some text

        -- Performs the post using the current page to extract field values:
        post "url/to/post/to" $ do
          addNonce -- Add the _nonce field with the currently shown value

          -- Lookup field by the text on the labels pointing to them.
          byLabel "Email:" ""
          byLabel "Password:" "secret"
          byLabel "Confirm:" "secret"

      it "Sends another form, this one has a file" $ do
        post "url/to/post/file/to" $ do
          -- You can add files this easy, you still have to provide the mime type manually though.
          addFile "file_field_name" "path/to/local/file" "image/jpeg"
          -- And of course you can add any field if you know it's name
          byName "answer" "42"

        statusIs 302

    describe "Db access, still very raw" $ do
      it "selects the list" $ do
        msgs <- testDB $ do (selectList [] [] :: SqlPersist IO [(Key SqlPersist Message, Message)])
        assertEqual "One Message in the DB" 1 (DL.length msgs)