繁体   English   中英

使用Hspec运行HUnit测试

[英]Running HUnit tests with Hspec

我想在规范内运行HUnit测试:

module SHCSpec (spec)
    where

import Test.Hspec
import Test.Hspec.Contrib.HUnit
import Test.HUnit

import SHC.Types
import SHC.Lix


spec :: Spec
spec = do
    fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
        [ Irrelevant @=? toHit []
        , None       @=? toHit [False]
        , None       @=? toHit [False, False]
        , Partial    @=? toHit [False, True]
        , Partial    @=? toHit [True, False]
        , Partial    @=? toHit [False, False, True]
        , Partial    @=? toHit [False, True, False]
        , Partial    @=? toHit [True, False, False]
        , Full       @=? toHit [True]
        , Full       @=? toHit [True, True]
        ])

上面的代码可以工作,但是会产生以下丑陋的输出:

SHC
  SHC.Lix
    toHit
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>
      <unlabeled>

是否可以将标签toHit到每个测试用例上? 像这样:

SHC
  SHC.Lix
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit
    toHit

更好的方法是在每个toHit案例toHit附加一个数字。 我搞砸了TestListmap TestLabel无济于事。

如何使用以下功能将标签附加到所有测试中:

label ts =
  [ show i ~: t | (i,t) <- zip [(1::Int)..] ts ]

只需在您的测试列表前面加上对label的调用即可:

spec :: Spec
spec = do
    fromHUnitTest ("SHC.Lix" ~: "toHit" ~:
        label
        [ Irrelevant @=? toHit []
        , None       @=? toHit [False]
        ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM