我對 Haskell 比較陌生,所以如果我的術語不太正確,請提前道歉。
我想為一個非常簡單的專案實施一些簡單的單元測驗,通過cabal. 我注意到這個非常相似的問題,但它并沒有真正幫助。這個也沒有(它提到tasty,見下文)。
我想我可以通過僅使用來實作這一點HUnit- 但是,我承認我對網上指南談論的所有其他“事物”有點困惑:
- 我不太明白介面
exitcode-stdio-1.0和detailed-0.9 - 我不確定使用
HUnitorQuickcheckor others 的差異(或中期和長期)含義? tastyHUnit指南提到的作用是什么。
因此,我嘗試將所有“附加”軟體包排除在外,并將其他所有內容都保留為“默認”,并盡我所能,并執行以下操作:
$ mkdir example ; mkdir example/test
$ cd example
$ cabal init
然后編輯example.cabal并添加了此部分:
Test-Suite test-example
type: exitcode-stdio-1.0
hs-source-dirs: test, app
main-is: Main.hs
build-depends: base >=4.15.1.0,
HUnit
default-language: Haskell2010
然后我test/Main.hs用這個內容創建:
module Main where
import Test.HUnit
tests = TestList [
TestLabel "test2"
(TestCase $ assertBool "Why is this not running," False)
]
main :: IO ()
main = do
runTestTT tests
return ()
最后,我嘗試運行全部內容:
$ cabal configure --enable-tests && cabal build && cabal test
Up to date
Build profile: -w ghc-9.2.4 -O1
In order, the following will be built (use -v for more details):
- example-0.1.0.0 (test:test-example) (additional components to build)
Preprocessing test suite 'test-example' for example-0.1.0.0..
Building test suite 'test-example' for example-0.1.0.0..
Build profile: -w ghc-9.2.4 -O1
In order, the following will be built (use -v for more details):
- example-0.1.0.0 (test:test-example) (ephemeral targets)
Preprocessing test suite 'test-example' for example-0.1.0.0..
Building test suite 'test-example' for example-0.1.0.0..
Running 1 test suites...
Test suite test-example: RUNNING...
Test suite test-example: PASS
Test suite logged to:
/home/jir/workinprogress/haskell/example/dist-newstyle/build/x86_64-linux/ghc-9.2.4/example-0.1.0.0/t/test-example/test/example-0.1.0.0-test-example.log
1 of 1 test suites (1 of 1 test cases) passed.
而且輸出不是我所期望的。我顯然在做一些根本錯誤的事情,但我不知道它是什么。
uj5u.com熱心網友回復:
為了讓exitcode-stdio-1.0測驗型別識別失敗的套件,您需要安排測驗套件的main功能以失敗退出,以防出現任何測驗失敗。幸運的是,有一個runTestTTAndExit函式可以處理這個問題,所以如果你將你的替換main為:
main = runTestTTAndExit tests
它應該可以正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/528485.html
標籤:单元测试哈斯克尔阴谋单位
