Safe Haskell | None |
---|
- type SnapTesting b a = StateT (Handler b b (), SnapletInit b b, OutputStream TestLog) IO a
- type TestRequest = RequestBuilder IO ()
- data TestLog
- data SnapTestingConfig = SnapTestingConfig {
- reportGenerators :: [InputStream TestLog -> IO ()]
- defaultConfig :: SnapTestingConfig
- runSnapTests :: SnapTestingConfig -> Handler b b () -> SnapletInit b b -> SnapTesting b () -> IO ()
- consoleReport :: InputStream TestLog -> IO ()
- linuxDesktopReport :: InputStream TestLog -> IO ()
- name :: Text -> SnapTesting b () -> SnapTesting b ()
- get :: ByteString -> TestRequest
- get' :: ByteString -> Map ByteString [ByteString] -> TestRequest
- post :: ByteString -> Map ByteString [ByteString] -> TestRequest
- params :: [(ByteString, ByteString)] -> Map ByteString [ByteString]
- succeeds :: TestRequest -> SnapTesting b ()
- notfound :: TestRequest -> SnapTesting b ()
- redirects :: TestRequest -> SnapTesting b ()
- redirectsto :: TestRequest -> Text -> SnapTesting b ()
- changes :: (Show a, Eq a) => (a -> a) -> Handler b b a -> TestRequest -> SnapTesting b ()
- changes' :: (Show a, Eq a) => (a -> a) -> Handler b b a -> SnapTesting b c -> SnapTesting b ()
- contains :: TestRequest -> Text -> SnapTesting b ()
- notcontains :: TestRequest -> Text -> SnapTesting b ()
- data FormExpectations a
- = Value a
- | ErrorPaths [Text]
- form :: (Eq a, Show a) => FormExpectations a -> Form Text (Handler b b) a -> Map Text Text -> SnapTesting b ()
- equals :: (Show a, Eq a) => a -> Handler b b a -> SnapTesting b ()
- assert :: Bool -> SnapTesting b ()
- cleanup :: Handler b b () -> SnapTesting b () -> SnapTesting b ()
- eval :: Handler b b a -> SnapTesting b a
- modifySite :: (Handler b b () -> Handler b b ()) -> SnapTesting b a -> SnapTesting b a
- quickCheck :: Testable prop => prop -> SnapTesting b ()
Types
type SnapTesting b a = StateT (Handler b b (), SnapletInit b b, OutputStream TestLog) IO aSource
The main type for this library, where b
is your application state,
often called App
. This is a State monad on top of IO, where the State carries
your application (or, more specifically, a top-level handler), and stream of test results
to be reported as passing or failing.
type TestRequest = RequestBuilder IO ()Source
TestLog is what is streamed to report generators. It is a flatten tree structure.
data SnapTestingConfig Source
SnapTestingConfig | |
|
Configuration
Running tests
:: SnapTestingConfig | Configuration for test runner |
-> Handler b b () | Site that requests are run against (often route routes, where routes are your sites routes). |
-> SnapletInit b b | Site initializer |
-> SnapTesting b () | Block of tests |
-> IO () |
Run a set of tests, putting the results through the specified report generators
consoleReport :: InputStream TestLog -> IO ()Source
Prints test results to the console. For example:
/auth/new_user success PASSED creates a new account PASSED
linuxDesktopReport :: InputStream TestLog -> IO ()Source
Sends the test results to desktop notifications on linux. Prints how many tests passed and failed.
Labeling
:: Text | Name of block |
-> SnapTesting b () | Block of tests |
-> SnapTesting b () |
Labels a block of tests with a descriptive name, to be used in report generation.
Creating Requests
:: ByteString | The url to request. |
-> Map ByteString [ByteString] | The parameters to send. |
-> TestRequest |
Creates a new GET request, with query parameters.
:: ByteString | The url to request. |
-> Map ByteString [ByteString] | The parameters to send. |
-> TestRequest |
Creates a new POST request, with a set of parameters.
:: [(ByteString, ByteString)] | Pairs of parameter and value. |
-> Map ByteString [ByteString] |
A helper to construct parameters.
Request predicates
succeeds :: TestRequest -> SnapTesting b ()Source
Checks that the given request results in a success (200) code.
notfound :: TestRequest -> SnapTesting b ()Source
Checks that the given request results in a not found (404) code.
redirects :: TestRequest -> SnapTesting b ()Source
Checks that the given request results in a redirect (3**) code.
:: TestRequest | Request to run |
-> Text | URL it should redirect to |
-> SnapTesting b () |
Checks that the given request results in a redirect to a specific url.
:: (Show a, Eq a) | |
=> (a -> a) | Change function |
-> Handler b b a | Monadic value |
-> TestRequest | Request to run. |
-> SnapTesting b () |
Checks that the monadic value given changes by the function specified after the request is run.
For example, if you wanted to make sure that account creation was creating new accounts:
changes (+1) countAccounts (post "/auth/new_user" $ params [ ("new_user.name", "Jane") , ("new_user.email", "jdoe@c.com") , ("new_user.password", "foobar")])
:: (Show a, Eq a) | |
=> (a -> a) | Change function |
-> Handler b b a | Monadic value |
-> SnapTesting b c | Block of tests to run |
-> SnapTesting b () |
A more general variant of changes
that allows an arbitrary block instead of a request.
:: TestRequest | Request to run |
-> Text | Text that body should contain |
-> SnapTesting b () |
Checks that the response body of a given request contains some text.
:: TestRequest | Request to run |
-> Text | Text that body should not contain |
-> SnapTesting b () |
Checks that the response body of a given request does not contain some text.
Form tests
data FormExpectations a Source
A data type for tests against forms.
Value a | The value the form should take (and should be valid) |
ErrorPaths [Text] | The error paths that should be populated |
:: (Eq a, Show a) | |
=> FormExpectations a | If the form should succeed, Value a is what it should produce. If failing, ErrorPaths should be all the errors that are triggered. |
-> Form Text (Handler b b) a | The form to run |
-> Map Text Text | The parameters to pass |
-> SnapTesting b () |
Test against digestive-functors forms.
Stateful unit tests
:: (Show a, Eq a) | |
=> a | Value to compare against |
-> Handler b b a | Handler that should evaluate to the same thing |
-> SnapTesting b () |
Checks that the handler evaluates to the given value.
Pure unit tests
assert :: Bool -> SnapTesting b ()Source
Helper to bring the results of other tests into the test suite.
Run actions after block
:: Handler b b () | Action to run after tests |
-> SnapTesting b () | Tests to run |
-> SnapTesting b () |
Runs an action after a block of tests, usually used to remove database state.
Evaluate arbitrary action
Create helpers
:: (Handler b b () -> Handler b b ()) | Site modification function |
-> SnapTesting b a | Tests to run |
-> SnapTesting b a |
Given a site to site function (like, generating a random user and logging in), run the given block of test with the modified state.
Integrate with QuickCheck
quickCheck :: Testable prop => prop -> SnapTesting b ()Source
Allows you to run a quickcheck test. All 100 test passing counts as a pass, any failure a failure. Currently the reporting is really bad (you don't see what the failing example is).