haskell HUnit 测试在 cabal 测试中不起作用

问题描述 投票:0回答:1

我尝试为简单的 haskell 项目运行测试:

这是阴谋集团部分:

test-suite tests-main
    type: exitcode-stdio-1.0
    main-is: tests.hs
    build-depends: base,HUnit
    hs-source-dirs: tests , app
    other-modules: MyModule
    default-language: Haskell2010

这是测试.hs:

module Main where

import Test.HUnit
import MyModule 

-- Create a test case
testWinV1 :: Test
testWinV1 = TestCase (assertEqual "Test1" True (f1 "data1"))

testWinV2 :: Test
testWinV2 = TestCase (assertEqual "Test2" True (f2 "data2"))

-- Create a test suite
tests :: Test
tests =
  TestList
    [ TestLabel "Test 1" testWinV1,
      TestLabel "Test 2" testWinV2
    ]

-- Run the test suite
-- main :: IO Counts
main = do
  runTestTT tests

如果我运行阴谋测试:

Running 1 test suites...
Test suite tests-main: RUNNING...
Test suite tests-main: PASS
...
1 of 1 test suites (1 of 1 test cases) passed.

所以它运行了一些东西,但不是我的测试..我做错了什么?

我尝试运行我的 2 个测试,但它运行了一些东西,但这不是我的测试..

haskell testing
1个回答
0
投票

什么也没发生,因为

exitcode-stdio-1.0
测试类型查看退出代码。

您已经使用了函数

runTestTT :: Test -> IO Counts
,它返回测试统计信息,但它对退出代码没有执行任何操作。

如果您不想对统计数据进行任何进一步的处理,只想在任何测试失败时失败,您应该使用

runTestTTAndExit :: Test -> IO ()
代替:

main :: IO ()
main = runTestTTAndExit tests
© www.soinside.com 2019 - 2024. All rights reserved.