Writing your Clojure tests in EDN files
10 months ago
- #clojure
- #automation
- #unit-testing
- Jacob O'Bryant discusses his simplified approach to unit testing, where input data is defined and expected return values are generated and stored in EDN files.
- The test runner evaluates the code, adds the result to the test file, and checks for changes via git diffs, eliminating the need for traditional pass/fail tests.
- Helper functions like `t/with-db` are used to populate in-memory databases for testing, making the process more straightforward and REPL-like.
- Exceptions in test cases are captured as data under an `:ex` key, and stack traces are truncated to focus on relevant frames.
- Intermediate values tapped during execution are included in test cases for inspection, enhancing debugging capabilities.
- The test runner function `run-examples!` can be integrated into file watchers to update test results automatically on file saves.