【问题标题】:Simple test cases in Haskell modulesHaskell 模块中的简单测试用例
【发布时间】:2014-02-10 12:28:41
【问题描述】:

我想在 Haskell 模块中编写自己的测试用例。可以说我制作了一个“范围”模块。我可能想检查一下:

(range 1 2) + (range 3 5) == (range 1 5)
(range 1 4) + empty == (range 1 4)

等等

我想将这些测试放在模块中,也许还有一些方法可以使用编译器标志打开/关闭它们。

我目前对某些为我生成测试用例的框架并不真正感兴趣,我很高兴自己这样做。

【问题讨论】:

标签: unit-testing haskell testing


【解决方案1】:

何不试试Tasty 的新热点。 Tasty 可以与 cabal 集成以进行集成构建/测试。

import Test.Tasty
import Test.Tasty.HUnit

import My.Range.Module

main = defaultMain unitTests

unitTests = testGroup "Unit tests" [
  testCase "Adding Continuous Ranges" $
    (range 1 2) + (range 3 5) @?= (range 1 5),
  testCase "Adding an empty Range" $
    (range 1 4) + empty @?= (range 1 4)]

有命令行选项

% ./test --help
Mmm... tasty test suite

Usage: ex [-p|--pattern ARG] [-l|--list-tests] [-j|--num-threads ARG]
          [-q|--quiet] [--hide-successes] [--smallcheck-depth ARG]
          [--quickcheck-tests ARG] [--quickcheck-replay ARG]
          [--quickcheck-max-size ARG] [--quickcheck-max-ratio ARG]

Available options:
  -h,--help                Show this help text
  -p,--pattern ARG         Select only tests that match pattern
  -l,--list-tests          Do not run the tests; just print their names
  -j,--num-threads ARG     Number of threads to use for tests execution
  -q,--quiet               Do not produce any output; indicate success only by
                           the exit code
  --hide-successes         Do not print tests that passed successfully
  --smallcheck-depth ARG   Depth to use for smallcheck tests
  --quickcheck-tests ARG   Number of test cases for QuickCheck to generate
  --quickcheck-replay ARG  Replay token to use for replaying a previous test run
  --quickcheck-max-size ARG
                           Size of the biggest test cases quickcheck generates
  --quickcheck-max-ratio ARG
                           Maximum number of discared tests per successful test
                           before giving up

您可以使用--pattern 选项仅选择要运行的特定测试

【讨论】:

    猜你喜欢
    • 2014-02-16
    • 1970-01-01
    • 2013-04-09
    • 2012-10-13
    • 1970-01-01
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多