Skip to content

Fast and pretty Clojure test runner

Notifications You must be signed in to change notification settings

pithyless/eftest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eftest

Eftest is a fast and pretty Clojure test runner.

Installation

To install, add the following to your project :dependencies:

[eftest "0.3.2"]

Alternatively, if you just want to use Eftest as a lein test replacement, add the following to your project :plugins:

[lein-eftest "0.3.2"]

Screenshots

When all the tests pass, it looks like this:

Passing example

When a test fails, it looks like:

Failing example

And when a test throws an exception, it looks like:

Erroring example

Usage

Library

Eftest has two main functions: find-tests and run-tests.

The find-tests function searches a source, which can be a namespace, directory path, symbol, var, or a collection of any of the previous. It returns a collection of test vars found in the source.

The run-tests function accepts a collection of test vars and runs them, delivering a report on the tests as it goes.

Typically these two functions are used together:

user=> (require '[eftest.runner :refer [find-tests run-tests]])
nil
user=> (run-tests (find-tests "test"))
...

The above example will run all tests found in the "test" directory.

By default Eftest runs tests in parallel, which can cause issues with tests that expect to be single-threaded. To disable this, set the :multithread? option to false:

user=> (run-tests (find-tests "test") {:multithread? false})

Alternatively, you can add the :eftest/synchronized key as metadata to any tests you want to force to be executed in serial:

(deftest ^:eftest/synchronized a-test
  (is (= 1 1)))

Or you can synchronize the entire namespace:

(ns ^:eftest/synchronized foo.core-test
  (:require [clojure.test :refer :all]
            [foo.core :refer :all]))

You can also change the reporting function used. For example, if you want a colorized reporter but without the progress bar:

user=> (run-tests (find-tests "test") {:report eftest.report.pretty/report})

Or JUnit output:

user=> (run-tests (find-tests "test") {:report clojure.report.junit/report})

Or maybe you just want the old Clojure test reporter:

user=> (run-tests (find-tests "test") {:report clojure.test/report})

If you want to redirect reporting output to a file, use the eftest.report/report-to-file function:

user=> (require '[clojure.report :refer [report-to-file]])
nil
user=> (require '[clojure.report.junit :as ju])
nil
user=> (run-tests (find-tests "test") {:report (report-to-file ju/report "test.xml")})

Plugin

To use the Lein-Eftest plugin, just run:

lein eftest

You can customize the reporter and set the concurrency by adding an :eftest key to your project map:

:eftest {:multithread? false
         :report clojure.report.junit/report
         ;; You can optionally write the output to a file like so:
         :report-to-file "target/junit.xml"}

Leiningen test selectors also work. With namespaces:

lein eftest foo.bar-test foo.baz-test

And with metadata keywords:

lein eftest :integration

License

Copyright © 2017 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Fast and pretty Clojure test runner

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Clojure 100.0%