如何使用包含测试的多个模块的test-framework-th?

时间:2014-04-13 18:59:40

标签: unit-testing haskell test-framework

我想使用test-framework-th来生成测试组。

我有这个主要测试模块:

module Main where

import           Test.Framework.TH

import           Foo.Test

main = $(defaultMainGenerator)

此模块包含测试:

module Foo.Test where

import           Test.HUnit

case_1 = do 1 @=? 2

但是,defaultMainGenerator未检测到Foo.Test模块中的测试。它仅检测调用它的模块中的测试(在本例中为Main)。

如何在不重复模板的情况下跨模块拆分我的测试?

1 个答案:

答案 0 :(得分:0)

在每个模块中使用testGroupGenerator为该模块生成测试组,然后使用main中的测试组,例如

Foo.hs:

module Foo where
import Test.Framework.TH
tests = $(testGroupGenerator)
...

Bar.hs:

module Bar where
import Test.Framework.TH
tests = $(testGroupGenerator)
...

Main.hs:

import Test.Framework

import Foo
import Bar

main = defaultMain [Foo.tests, Bar.tests]
相关问题