-
Notifications
You must be signed in to change notification settings - Fork 128
Autotest
In the jargon, "autotesting" refers to a program that watches for changes to files. When it sees a file change, it reruns any tests that depend on the changed file. Midje supports autotesting.
There are two simple ways to use it, from the command line and from the repl.
Command line:
% lein midje autotest
Repl:
user=> (use 'midje.repl)
user=> (autotest)
Autotest tracks changes in files. That is, if namespace TEST depends on namespace SOURCE, a change to SOURCE will cause TEST to be reloaded. If TEST contains facts, they will be rechecked.
Rechecking happens even if the dependency is indirect. If TEST depends on INTERMEDIATE, which depends on SOURCE, a change in SOURCE will cause TEST to be reloaded.
When used as shown above, autotesting tracks changes in the Leiningen project's :test-paths
and :source paths
.
Autotesting works on filesystem directories. (This is a consequence of the library Midje uses.) You can restrict the directories it considers using the :dirs
argument. Like this:
Command line:
% lein midje autotest :dirs dir1 dir2
Repl:
user=> (autotest :dirs dir1 dir2)
Note that choosing particular directories can cause changes to be missed. Consider the above example, where TEST depends on INTERMEDIATE, which depends on SOURCE. If INTERMEDIATE is not in one of the watched directories, a change in SOURCE won't cause TEST to be reloaded.
By default, autotesting checks for changes twice each second. That can't be changed from the commmand line. It can be changed in the repl:
user=> (autotest :interval 1000)
Since intervals are measured in milliseconds, that checks once per second.