我花了几个小时试图获得一个基本的测试框架来测试Yesod处理程序。我还有一些麻烦。查看一个完整的工作示例会很有用,其中包括与数据库的交互。
有人可以引导我访问网络上的任何示例吗?理想情况下是一个开源的yesod项目,所以我可以完整地看到脚手架。我从不同的来源找到了一些零碎的东西,但到目前为止他们并没有帮助我那么多。
答案 0 :(得分:1)
我不认为它们是特别好的测试用例(有很多重复,并且数据库不会在测试用例之间自动擦除),但你可以看一下these specs我为{{3}做的}}。整个项目的开源this website。
以下是一个示例:
homeSpecs :: Spec
homeSpecs =
ydescribe "These are some example tests" $ do
yit "loads the index and checks it looks right" $ do
_ <- runDB $ rawExecute "TRUNCATE TABLE hack_day, project;" []
get HackDayR
statusIs 200
htmlAnyContain "h2" "New Hackday"
yit "shows the current hackday" $ do
_ <- runDB $ rawExecute "TRUNCATE TABLE hack_day, project;" []
currentTime <- liftIO $ getCurrentTime
_ <- runDB $ insert $ HackDay { hackDayTitle = "testTitle"
, hackDayCreated = currentTime
, hackDayVotingClosed = False }
get HackDayR
htmlAllContain ".currentHackday" "testTitle"