This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-01
Channels
- # announcements (2)
- # babashka (26)
- # beginners (26)
- # biff (18)
- # boulder-clojurians (2)
- # cider (16)
- # clj-kondo (34)
- # cljs-dev (4)
- # clojure (22)
- # clojure-denver (10)
- # clojure-europe (16)
- # clojure-nl (1)
- # clojure-norway (10)
- # clojure-uk (2)
- # clojurescript (25)
- # conjure (3)
- # cursive (11)
- # datomic (11)
- # dev-tooling (6)
- # emacs (6)
- # etaoin (7)
- # events (1)
- # fulcro (6)
- # humbleui (11)
- # hyperfiddle (15)
- # instaparse (2)
- # introduce-yourself (2)
- # jobs-discuss (1)
- # lsp (26)
- # malli (7)
- # reitit (5)
- # releases (1)
- # sci (6)
- # shadow-cljs (16)
- # specter (5)
- # vim (5)
Hey, came across biff today. Looks really cool. I started playing with it, and wondered what the best approach would be to writing tests involving the DB? Would speculative transactions be the way to go? or something else?
Yes, speculative transactions are a good way to go. I have a few tests for the biff/submit-tx
function you can use as a starting point: https://github.com/jacobobryant/biff/blob/master/test/com/biffweb/impl/xtdb_test.clj
(There are a couple tests in there that use with-tx
, though most of the tests just set up a test db and run some queries)
I guess the main thing is you can set up an in-memory node/db with dummy data and then use it however you like, whether that means speculative transactions, queries, or even regular transactions + await-tx
Hmm, that would mean "bypassing" the biff/tx wrapper right?
biff/submit-tx
If you do speculative transactions, yes. So actually perhaps just calling biff/submit-tx
on the in-memory node would be the way to go.
Would you use fixtures to setup an in memory DB/publish schema between each test?
I see you use (defn test-node [docs]
for a lot of your tests
I would copy and paste test-node
, schema
and malli-opts
from the file I linked, then follow the (with-open [node ...
pattern
Correct
Right
for calling submit-tx you can do (biff/submit-tx {:biff.xtdb/node node, :biff/malli-opts malli-opts} ...)
, then call (xt/db node)
to get a db value that includes the submitted transaction.
Is there a good way for higher level (integration(ish)) tests? like, set everything up, trigger a route, tear it all down again. Potentially in parallel with other tests doing similar stuff?
I guess it would be some variant of the default start
method - returning a system you can use for a test/set of tests
I haven't set up any tests like that myself (I honestly just do manual testing for the most part), so it's not a beaten path so to speak, but yes if you create an alternate start
fn that should do the trick.
Nice, thanks 👍 - gonna have a play around with this.
Sounds good! Let me know how it goes. I would like to flesh out the (mostly nonexistent) testing story at some point; it wouldn't hurt to have some more stuff built in.