2014-04-13 16 views
0

我想使用test-framework-th来生成测试组。如何在包含测试的多个模块中使用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)。

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

回答

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] 
+0

似乎是唯一的选择。 :[我想我只是使用自定义预处理器来生成'main'。 – rightfold

相关问题