The recommended tooling topic is excellent and particularly valuable for newcomers but I couldn’t find anything similar for testing in PureScript. I’ve pulled together some links to libraries and examples below and hope that together with some comments we might stumble our way toward some newcomer-friendly testing recommendations for PureScript.
PureScript Spec is a testing framework, inspired by Haskell’s hspec, that provides a DSL for writing write synchronous and asynchronous tests. A guide is available. It can be used to run tests defined by QuickCheck.
Test-Unit is an asynchronous test runner which can also run QuickCheck tests.
Assert is a basic assertions library for low level testing. It is primarily for testing the core libraries that cannot use QuickCheck without resulting in circular dependencies.
Proxy is not a testing library but can be useful in “passing types” into functions, which is often helpful when using QuickCheck.
Jordan Martinez’s repo Jordan’s reference contains excellent examples and notes on testing. Had I known about it before I may not have bothered with this post. Start with the readme files in 21-Hello-World/07-Testing and 21-Hello-World/07-Testing/test.
- Use QuickCheck. If you can think of a property to test, test it with QuickCheck
- Use PureScript Spec for simple assertions, testing against external APIs and running QuickCheck tests
- Whenever you define a type, instantiate the
Arbitrarytypeclass, if possible
- If a type is constrained:
- Document in comments which values are acceptable and which are not
- Do not export its constructor but provide safe ways to construct it
- Provide a
isValid :: a -> Booleanfunction that can be used to check that a value of that type meets the constraints
- Write a test that ensures that
Arbitrarygenerates valid values
- Test that each function that returns a value of this type returns a valid value
This document exists mostly to extract knowledge from the PureScript community via comments. All comments, especially on the provisional recommendations, are welcome.