-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathWRITING-TESTS
42 lines (30 loc) · 1.38 KB
/
WRITING-TESTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Do what is EASIEST. Having a test at all is more important than,
say, pretty failure output.
To add a test, open Main.hs, and add an entry to tests, e.g.:
tests :: [TestEnv -> Test]
tests =
[ ...
, TestLabel "Foo" . testFoo
]
testFoo :: TestEnv -> Test
testFoo TestEnv{..} = TestCase $ do
meaningOfLife @?= 42
2013 <- getCurrentYear
return ()
Mnemonic for HUnit @=? and @?= operators:
* `?` is the value whose correctness is in question
* `=` is the expected value
If you move a test to a separate module, don't forget to add it to
"other-modules" in postgresql-simple.cabal . Otherwise, the module will be
left out of the tarball generated by `cabal sdist`, and tests will fail to
build when installing from Hackage.
'TestEnv' (defined in Common.hs) contains information for accessing the
database. `TestEnv{..}` is a record wildcard which brings the following
definitions into scope:
conn :: Connection
withConn :: (Connection -> IO a) -> IO a
'conn' is a database connection shared by all the tests.
'withConn' can be used to open additional connections (to the same database).
'Test' is basically a tree of 'Assertion's, where 'Assertion' is just a type
alias for IO (). See the [HUnit documentation][1] for more information.
[1]: http://hackage.haskell.org/packages/archive/HUnit/latest/doc/html/Test-HUnit-Base.html