Should mount/stop restore previous states that were overridden using mount/start-with?
I'm trying to run tests within the same process where I have development REPL
@jarppe: right mount/stop
would "restore" previous states overridden with mount/start-with
or swap
. are you running tests after you did mount/stop
, so any of the dev states would not interfere?
you can also start a standalone repl just for tests that would watch for changes and rerun. this would be a lot cleaner than running tests within the same repl as you develop.
depending on your build tool you can use either: https://github.com/jakemcc/lein-test-refresh or https://github.com/adzerk-oss/boot-test (i.e. boot watch speak test
)
@tolitius: I have app started with (mount/start), the in my tests I try to override DB with (mount/start-with {#'..../db test-db}) and after the tests are done I call (mount/stop). How ever, after the (mount/stop) it seems that all states are in mount.core.NotStartedState state.
I agree that in general running tests in separate process is better most of the time
ah.. yes, (mount/stop)
would stop all the states, and then would bind them to a NotStartedState
so the state definitions would still be restored: i.e. your db state's start and stop functions will revert back from the test ones
but the states values will be NotStartedState
after (mount/stop)
Right, that clears what's going on. Is there some way to restore the previous state values?
hm.. there should not have been any values previously, since you would need to run (mount/stop)
before running the tests not to clash the test states run with the dev values
i.e. if you have a started db conn in dev, it would need to be stopped before running a test with it
Yes, that works. Stop everything before tests and start after tests.
It's just a bit difficult to figure out where this start/stop should happen so that I could run tests both in dev repl, and stand alone "lein test".
does it take time (to restart after tests), or there are other reasons you would not want to restart?
if you run your tests in a standalone repl, unless your tests use the same connections (i.e. same db url user/pass), you don't have to stop anything in your dev repl
No, stop & start is fast, it's just to figure out where to do stop and start. If I put them into clojure.test/use-fixtures the get executed in standalone test runs as well.
I think I'll just run tests on separate process, that's easier.
🙂 and cleaner. but just to recap: you can call (mount/stop)
before running any tests and you should be good. so whether it is in fixtures or in repl, both should work. (mount/stop)
calls take no time if there is nothing to stop, so you can include them before each test if that helps your workflow.
Right, thanks for your help.
and if you run it in a separate repl, I would recommend lein-test-refresh
or boot watch speak test
: let it work for you rather than manually rerun them every time