यहाँ इस
> tree
.
├── example.cabal
├── app
│ └── Main.hs
├── ChangeLog.md
├── LICENSE
├── Setup.hs
├── src
│ ├── A
│ │ └── C.hs
│ ├── A.hs
│ └── B.hs
├── stack.yaml
└── tst
├── integration
│ └── Spec.hs
└── unit
├── A
│ └── CSpec.hs
├── ASpec.hs
├── BSpec.hs
└── Spec.hs
आप एकीकरण परीक्षणों कि सामान्य इकाई परीक्षण और कई उप मॉड्यूल है कि आपके src
-folder में प्रत्येक मॉड्यूल के अनुरूप से अलग हैं करना चाहते हैं की तरह एक निर्देशिका संरचना के लिए एक सेटअप है
सब आप अपने
example.cabal
फाइल करने के लिए परीक्षण स्वीट जोड़ने की जरूरत के पहले
name: example
...
-- copyright:
-- category:
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
executable testmain
main-is: Main.hs
hs-source-dirs: app
build-depends: base
, example
library
exposed-modules: A.C,A,B
-- other-modules:
-- other-extensions:
build-depends: base >=4.9 && <4.10
hs-source-dirs: src
default-language: Haskell2010
test-suite unit-tests
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: tst/unit
build-depends: base
, example
, hspec
, hspec-discover
, ...
test-suite integration-tests
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: tst/integration
build-depends: base
, example
, hspec
, ...
अपने tst/unit/Spec.hs
यह hspec-discover
से है और यह पता चलता है (इसलिए नाम) में निम्नलिखित डाल प्रपत्र ...Spec.hs
के सभी मॉड्यूल और उन मॉड्यूल में से प्रत्येक से spec
समारोह निष्पादित करता है।
tst/unit/Spec.hs
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
सिर्फ इस एक पंक्ति
अन्य परीक्षण tst/integration
फ़ोल्डर
में फ़ाइलों
फिर अपने ASpec.hs
में अपनी इकाई परीक्षण जोड़ने के लिए, और BSpec.hs
, CSpec.hs
और अपने Spec.hs
में दूसरों
module ASpec where
import Test.Hspec
import A
spec :: Spec
spec = do
describe "Prelude.head" $ do
it "returns the first element of a list" $ do
head [23 ..] `shouldBe` (23 :: Int)
it "returns the first element of an *arbitrary* list" $
property $ \x xs -> head (x:xs) == (x :: Int)
it "throws an exception if used with an empty list" $ do
evaluate (head []) `shouldThrow` anyException
आप तो संकलन और
$> stack test
# now all your tests are executed
$> stack test :unit-tests
# now only the unit tests run
$> stack test :integration-tests
# now only the integration tests run
सूत्रों का कहना है
के साथ अपने परीक्षण चला सकते हैं
आप https://hspec.github.io बिल्कुल उदाहरण मिल सकते हैं, अगर आप hspec शैली परीक्षण के बारे में अधिक जानने के लिए मुझे लगता है कि यह सबसे अच्छा होगा चाहते हैं वहां शुरू करने के लिए। ढेर के लिए - https://haskellstack.org पर जाएं - वहां परीक्षण/बेंचमार्किंग के बारे में कुछ जानकारी है - मेरा मतलब परीक्षण और बेंचमार्क चलाने के बारे में है।
हैकेल में विभिन्न परीक्षण शैली के लिए हनीट, क्विक चेक, स्मॉलचेक, सिद्धांत (यदि मैं भूल गया हूं, मेरी प्यारी माफी मांगती है - वे हैं जिन्हें मैं नियमित रूप से भी उपयोग करता हूं)।
आप 'कैबल' फ़ाइल में स्टैक के परीक्षण (और अन्य) व्यवहार को कॉन्फ़िगर कर सकते हैं। परीक्षण अनुभाग – Lazersmoke
@Lazersmoke मुझे पता है कि '.abal' फ़ाइल में एक अनुभाग है। क्या आपके पास एकाधिक परीक्षण फ़ाइलों के लिए इस कॉन्फ़िगरेशन को कैसे करें इस पर एक उदाहरण है? मुझे अभी तक एक स्पष्ट उदाहरण नहीं मिला है, इसलिए सवाल पूछ रहा है – haiqus