如何在Yesod应用程序中运行单个测试?

时间:2014-09-24 08:37:34

标签: haskell yesod hspec

Yesod提供yesod test工具。测试是Spec类型的值,可以由hspec执行。

脚手架附带tests/HomeTest.hs中的预定义规范,在tests/main.hs中显式调用,该文件在运行yesod test时显然已编译并执行。我假设您应该在创建时将所有规范手动添加到main.hs,尽管可能有一种方法可以使用hspec' automated test discovery

这对回归测试很有用,但是测试驱动开发呢?在开发期间编写单个测试然后重复运行它的正确方法是什么? yesod test的帮助文字表明无法执行此操作:

$ yesod test --help
Usage: yesod test
  Build and run the integration tests

直接运行spec文件并不起作用(我想你不会期望它,因为它不包含main定义):

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

我不确定为什么我的项目的可执行文件被禁用。我应该改变吗?或者我应该创建main.hs的临时副本并注释掉所有其他测试?什么是最干净的解决方案?

0 个答案:

没有答案