Hi everyone!
Just wanted to announce a new release of my library for testing Fennel
code: v0.1.50! It's a pretty big update - I've changed a lot of things,
and further enhanced the ability to configure custom reporters.
You can find the library here: https://gitlab.com/andreyorst/fennel-test
A lot of changes are internal, so here's a brief list of user-visible
changes.
# Ability to skip tests
I've added a new function `skip-test` that accepts a message, and it
gets displayed in the reporter. It comes with a new status for tests,
that is treated as successful, but displays the SKIP message.
# Test stats
All default reporters now report the total amount of tests, the time it
took to execute tests, the total amount of assertions, the amount of
skipped tests, warnings, and errors.
By default, it looks something like this:
> Ran 37 tests in 28.5740 seconds with 1016 assertions, 0 skipped, 0 warnings, 0 errors
You can further customize how this info is displayed in the stats-report
callback, as well as other callbacks. For example, one of my projects
reports longest-running namespaces and individual tests like this:
> Test run at Tue Aug 20 01:54:51 2024, seed: 1724108091410
> ...
> ┌─ Running tests in test.client-test
> │┌─ multipart-post-test: PASS
> │├─ post-test: PASS
> │├─ query-parameters-test: PASS
> │└─ chunked-post-test: PASS
> └─ PASS
>
> Top 3 slowest namespaces (28.5422 seconds, 99.89% of total time)
> test.httpbin-test
> 2.6547 seconds average (21.2378 seconds / 8 tests)
> test.client-test
> 1.7822 seconds average (7.1289 seconds / 4 tests)
> test.json-test
> 0.0292 seconds average (0.1755 seconds / 6 tests)
>
> Top 3 slowest tests (23.4749 seconds, 82.15% of total time)
> test.httpbin-test/errornous-response-test took 17.4857 seconds
> test.client-test/query-parameters-test took 4.0585 seconds
> test.httpbin-test/delayed-response-test took 1.9307 seconds
If you want to see how it's done, check out the .fennel-test file in the
fnl-http project:
https://gitlab.com/andreyorst/fnl-http/-/blob/6fc5db549333bc320e1906b540263f6ba33aaece/.fennel-test
# Test failure context
If you've been using fennel-test and wondered what's the purpose of the
`testing` macro, as it seemed useless - you weren't wrong! It was
useless before, but now it is less useless - you can get a more
meaningful test report with it.
For example, here's a test that fails:
> (deftest deep-equality-test
> (testing "tables are equal"
> (assert-eq {:foo ["bar" "baz"]} {:foo ["bar" "qux"]})))
When we run it, we'll see:
> Error in 'example-test' in test 'deep-equality-test':
> testing: tables are equal
> runtime error: assertion failed for expression:
> (eq {:foo ["bar" "baz"]} {:foo ["bar" "qux"]})
> Left: {:foo ["bar" "baz"]}
> Right: {:foo ["bar" "qux"]}
The "testing: tables are equal" message is now displayed, giving you
some context.
`testing` macros can be nested too:
> (deftest deep-equality-test
> (testing "equality works on"
> (testing "tables"
> (assert-eq {:foo :bar} {:foo :bar}))
> (testing "arrays"
> (assert-eq [1 2 3] [4 5 6]))))
Again, running the test displays the error context:
> Error in 'example-test' in test 'deep-equality-test':
> testing: equality works on arrays
> runtime error: assertion failed for expression:
> (eq [1 2 3] [4 5 6])
> Left: [1 2 3]
> Right: [4 5 6]
This time the message is "testing: equality works on arrays", which was
constructed based on nested `testing` calls.
That's all for now! It was exciting to work on fennel-test again, and I
hope it will be useful to someone!
--
Andrey Listopadov
Andrey Listopadov <andreyorst@gmail.com> writes:
> Just wanted to announce a new release of my library for testing Fennel
> code: v0.1.50! It's a pretty big update - I've changed a lot of things,
> and further enhanced the ability to configure custom reporters.
Congratulations on the release.
It's great to see you back again. =)
-Phil