• Stars
    star
    769
  • Rank 56,868 (Top 2 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Full featured next gen Clojure test runner

Full featured next generation test runner for Clojure.

Jump to Quick start | Docs

Projects

Project CI Docs Release Coverage
kaocha CircleCI cljdoc badge Clojars Project codecov
kaocha-cljs CircleCI cljdoc badge Clojars Project codecov
kaocha-cucumber CircleCI cljdoc badge Clojars Project codecov
kaocha-junit-xml CircleCI cljdoc badge Clojars Project codecov
kaocha-cloverage CircleCI cljdoc badge Clojars Project codecov
kaocha-boot CircleCI cljdoc badge Clojars Project codecov
deep-diff CircleCI cljdoc badge Clojars Project codecov

考察 [kǎo chá]

  • to inspect
  • to observe and study
  • on-the-spot investigation

See the Line Dict entry for an audio sample.

Need help?

Are you

There is also a #kaocha channel on Clojurians Slack (sign up here), where users can help each other.

Docs

Features

Features include

  • Filtering tests based on test names or metadata
  • Watch mode: watch the file system for changes and re-run tests
  • Pretty, pluggable reporting
  • Randomize test order
  • Detect when interrupted with ctrl-C and print report
  • Fail fast mode: stop at first failure and print report
  • Profiling (show slowest tests)
  • Dynamic classpath handling
  • Tests as data (get test config, test plan, or test results as EDN)
  • Extensible test types (clojure.test, Midje, ...)
  • Extensible through plugins
  • Tool agnostic (Clojure CLI, Leiningen, ...)

Quick start

This is no replacement for reading the docs, but if you're particularly impatient to try it out, or if you already know Kaocha and need a quick reference how to set up a new project, then this guide is for you.

Clojure CLI (tools.deps)

Add Kaocha as a dependency, preferably under an alias.

;; deps.edn
{:deps { ,,, }
 :aliases
 {:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.88.1376"}}
         :main-opts ["-m" "kaocha.runner"]}}}

Add a binstub called bin/kaocha

mkdir -p bin
echo '#!/usr/bin/env sh' > bin/kaocha
echo 'clojure -M:test "$@"' >> bin/kaocha
chmod +x bin/kaocha

If you're on windows and installed clojure into powershell then you can put this into kaocha.ps1 for use with powershell.exe

clojure -M:test "$args"

Or put this in kaocha.bat for use with cmd.exe

powershell -command clojure -M:test "%*"

Or put this in kaocha for use with msys2

powershell -command clojure -M:test "$@"

Leiningen

Add a profile and alias

;; project.clj
(defproject my-proj "0.1.0"
  :dependencies [,,,]
  :profiles {:kaocha {:dependencies [[lambdaisland/kaocha "1.88.1376"]]}}
  :aliases {"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]})

Add a binstub called bin/kaocha

mkdir -p bin
echo '#!/usr/bin/env sh' > bin/kaocha
echo 'lein kaocha "$@"' >> bin/kaocha
chmod +x bin/kaocha

Boot

In your build.boot add the Kaocha dependency, and import the Kaocha task

;; build.boot
(set-env! :source-paths #{"src"}
          :dependencies '[[lambdaisland/kaocha-boot "..."]])

(require '[kaocha.boot-task :refer [kaocha]])

Add a binstub called bin/kaocha

mkdir -p bin
echo '#!/usr/bin/env sh' > bin/kaocha
echo 'boot kaocha "$@"' >> bin/kaocha
chmod +x bin/kaocha

Clojure CLI (tools.deps) :exec-fn alternative

We also support using the Clojure CLI :exec-fn/-X. However, we recommend the binstub approach above because it allows you to use traditional long and short options. If you nonetheless prefer :exec-fn/-X, you can set up deps.edn:

;; deps.edn
{:deps { ,,, }
 :aliases
 {:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.88.1376"}}
         :exec-fn kaocha.runner/exec-fn
         :exec-args {}}}}

And then Kaocha can be invoked this way: clojure -X:test

Generally speaking, we recommend using tests.edn for all of your configuration rather than putting it in exec-args unless there's an alternative combination of options you frequently run.

In that case, you can put configuration options :exec-args as though it were tests.edn. Let's say you frequently use watch with :fail-fast and a subset of tests skipped. You could save that configuration with an additional alias: clojure -X:watch-test like so:

;; deps.edn
{:deps { ,,, }
 :aliases
 {:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.88.1376"}}
         :exec-fn kaocha.runner/exec-fn
         :exec-args {}}
 :watch-test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.88.1376"}}
         :exec-fn kaocha.runner/exec-fn
         :exec-args {:watch? true
	 :skip-meta :slow
	 :fail-fast? true }}}}

If you wanted to turn off fail-fast temporarily, you could run clojure -X:watch-test :fail-fast? false

You can also pass exec-args on the command line like so:

clojure -X:test :print-config true :kaocha.plugin.randomize/seed 603964682

Babashka

Kaocha is compatible with Babashka.

You can create a bb.edn file:

{:paths ["src" "test"]
 :deps {lambdaisland/kaocha {:mvn/version "1.88.1376"}}}

Then you can create a binstub named bin/kaocha-bb:

#!/usr/bin/env bash
bb -m kaocha.runner/-main  $@

If you exclusively want to run tests using Babashka, you can of course call it bin/kaocha.

All tools

By default, Kaocha assumes that:

  • source files are in the src/ folder,
  • test files are in the test/ folder,
  • all test namespaces names end with -test (e.g. my-project.core-test). Also, the default test suite id is :unit (just unit on the command line).

If your tests don't seem to run (outcome is 0 tests, 0 assertions, 0 failures) you may need to write up your own configuration: add a tests.edn at the root of the project to configure actual test and source paths, and optionally set a reporter or load plugins (cf. Configuration in the documentation).

Example of a catch-all tests.edn config file (should run all tests found in src/ and /test, in any namespace).

#kaocha/v1
{:tests [{:id          :unit
          :test-paths  ["test" "src"]
          :ns-patterns [".*"]}]
          ;; :reporter kaocha.report.progress/report
          ;; :plugins [:kaocha.plugin/profiling :kaocha.plugin/notifier]
 }

Warning: this is not an optimal configuration. To avoid extra churn, you should try and target only folders and namespaces that actually contain tests.

Run your tests

bin/kaocha

# Watch for changes
bin/kaocha --watch

# Exit at first failure
bin/kaocha --fail-fast

# Only run the `unit` suite
bin/kaocha unit

# Only run a single test
bin/kaocha --focus my.app.foo-test/bar-test

# Use an alternative config file
bin/kaocha --config-file tests_ci.edn

# See all available options
bin/kaocha --test-help

Third party projects

  • kaocha-noyoda Don't speak like Yoda, write (is (= actual expected)) instead of (is (= expected actual))
  • kaocha-test-ns-hook A Kaocha plugin for the test-ns-hook feature in cloure.test.

Requirements

Kaocha requires Clojure 1.9 or later.

Lambda Island Open Source

Thank you! kaocha is made possible thanks to our generous backers. Become a backer on OpenCollective so that we can continue to make kaocha better.

 

kaocha is part of a growing collection of quality Clojure libraries created and maintained by the fine folks at Gaiwan.

Pay it forward by becoming a backer on our OpenCollective, so that we continue to enjoy a thriving Clojure ecosystem.

You can find an overview of all our different projects at lambdaisland/open-source.

 

 

Contributing

We warmly welcome patches to kaocha. Please keep in mind the following:

  • adhere to the LambdaIsland Clojure Style Guide
  • write patches that solve a problem
  • start by stating the problem, then supply a minimal solution *
  • by contributing you agree to license your contributions as EPL 1.0
  • don't break the contract with downstream consumers **
  • don't break the tests

We would very much appreciate it if you also

  • update the CHANGELOG and README
  • add tests for new functionality

We recommend opening an issue first, before opening a pull request. That way we can make sure we agree what the problem is, and discuss how best to solve it. This is especially true if you add new dependencies, or significantly increase the API surface. In cases like these we need to decide if these changes are in line with the project's goals.

* This goes for features too, a feature needs to solve a problem. State the problem it solves first, only then move on to solving it.

** Projects that have a version that starts with 0. may still see breaking changes, although we also consider the level of community adoption. The more widespread a project is, the less likely we're willing to introduce breakage. See LambdaIsland-flavored Versioning for more info.

License

Copyright © 2018-2023 Arne Brasseur and contributors

Available under the terms of the Eclipse Public License 1.0, see LICENSE.txt

More Repositories

1

regal

Royally reified regular expressions
Clojure
317
star
2

deep-diff2

Deep diff Clojure data structures and pretty print the result
Clojure
286
star
3

uri

A pure Clojure/ClojureScript URI library
Clojure
238
star
4

trikl

Terminal UI library for Clojure
Clojure
142
star
5

witchcraft

Clojure API for manipulating Minecraft, based on Bukkit
Clojure
130
star
6

glogi

A ClojureScript logging library based on goog.log
Clojure
119
star
7

fetch

ClojureScript wrapper for the JavaScript fetch API
Clojure
119
star
8

uniontypes

Union Types (ADTs, sum types) built on clojure.spec
Clojure
115
star
9

ornament

Clojure Styled Components
Clojure
115
star
10

classpath

Classpath/classloader/deps.edn related utilities
Clojure
82
star
11

corgi

Emacs Lisp
75
star
12

launchpad

Clojure/nREPL launcher
Clojure
64
star
13

metabase-datomic

Datomic driver for Metabase
Clojure
63
star
14

chui

Clojure
60
star
15

npmdemo

Demo of using Node+Express with ClojureScript
Clojure
60
star
16

funnel

Transit-over-WebSocket Message Relay
Clojure
56
star
17

deja-fu

ClojureScript local time/date library with a delightful API
Clojure
47
star
18

facai

Factories for fun and profit. 恭喜發財!
Clojure
43
star
19

kaocha-cljs

ClojureScript support for Kaocha
Clojure
40
star
20

cljbox2d

Clojure
40
star
21

open-source

A collection of Clojure/ClojureScript tools and libraries
Clojure
39
star
22

witchcraft-workshop

materials and code for the ClojureD 2022 workshop on Minecraft+Clojure
Clojure
39
star
23

thirdpartyjs

Demonstration of how to use third party JS in ClojureScript
Clojure
38
star
24

kaocha-cucumber

Cucumber support for Kaocha
Clojure
37
star
25

dom-types

Implement ClojureScript print handlers, as well Datify/Navigable for various built-in browser types.
Clojure
36
star
26

ansi

Parse ANSI color escape sequences to Hiccup syntax
Clojure
31
star
27

kaocha-cloverage

Code coverage analysis for Kaocha
Clojure
31
star
28

embedkit

Metabase as a Dashboard Engine
Clojure
30
star
29

pennon

A feature flag library for Clojure
Clojure
29
star
30

plenish

Clojure
28
star
31

hiccup

Enlive-backed Hiccup implementation (clj-only)
Clojure
27
star
32

kaocha-cljs2

Run ClojureScript tests from Kaocha (major rewrite)
Clojure
25
star
33

edn-lines

Library for dealing with newline separated EDN files
Shell
24
star
34

witchcraft-plugin

Add Clojure support (and an nREPL) to any Bukkit-based Minecraft server
Clojure
23
star
35

garden-watcher

A component that watches-and-recompiles your Garden stylesheets.
Clojure
22
star
36

reitit-jaatya

Freeze your reitit routes and create a static site out of it
Clojure
20
star
37

data-printers

Quickly define print handlers for tagged literals across print/pprint implementations.
Clojure
18
star
38

lambdaisland-guides

In depth guides into Clojure and ClojureScript by Lambda Island
TeX
17
star
39

specmonstah-malli

Clojure
17
star
40

cli

Opinionated command line argument handling, with excellent support for subcommands
Clojure
16
star
41

faker

Port of the Ruby Faker gem
Clojure
14
star
42

nrepl-proxy

Proxy for debugging nREPL interactions
Clojure
13
star
43

puck

ClojureScript wrapper around Pixi.js, plus other game dev utils
Clojure
13
star
44

aoc_2020

Advent of Code 2020
Clojure
11
star
45

kaocha-junit-xml

JUnit XML output for Kaocha
Clojure
10
star
46

harvest

Flexible factory library, successor to Facai
Clojure
10
star
47

gaiwan_co

Website for Gaiwan GmbH
Clojure
8
star
48

nrepl

Main namespace for starting an nREPL server with `clj`
Clojure
8
star
49

zipper-viz

Visualize Clojure zippers using Graphviz
Clojure
8
star
50

exoscale

Clojure/Babashka wrapper for the Exoscale HTTP API
Clojure
7
star
51

webstuff

The web as it was meant to be
Clojure
7
star
52

birch

A ClojureScript/Lumo version of the Unix "tree" command
Clojure
7
star
53

corgi-packages

Emacs Packages developed as part of Corgi
Emacs Lisp
7
star
54

activities

Clojure
6
star
55

kanban

Episode 9. Reagent
Clojure
6
star
56

react-calculator

A calculator built with ClojureScript and React
JavaScript
6
star
57

souk

Clojure
6
star
58

logback-clojure-filter

Logback appender filter that takes a Clojure expression
Clojure
6
star
59

breakout

The retro game "Breakout". re-frame/Reagent/React/SVG.
Clojure
5
star
60

booklog

Keep track of the books you read (Auth with Buddy)
Clojure
5
star
61

funnel-client

Websocket client for Funnel + examples
Clojure
5
star
62

li40-ultimate

Code from episode 40: The Ultimate Dev Setup
Shell
5
star
63

l33t

Demo ClojureScript+Node.js app
JavaScript
5
star
64

ep47-interceptors

Accompanying code to Lambda Island episode 47. Interceptors.
Clojure
5
star
65

daedalus

"Path finding and Delaunay triangulation in 2D, cljs wrapper for hxdaedalus-js"
Clojure
5
star
66

ep43-data-science-kixi-stats

Clojure
4
star
67

lambwiki

A small wiki app to demonstrate Luminus
Clojure
4
star
68

new-project

Template for new projects
Emacs Lisp
3
star
69

kaocha-boot

Kaocha support for Boot
Clojure
3
star
70

component_example

Example code for the Lambda Island episodes about Component
Clojure
3
star
71

datomic-quick-start

Datomic Quickstart sample code
Clojure
3
star
72

redolist

TodoMVC in re-frame
Clojure
3
star
73

rolodex-gui

Reagent app for testing the Rolodex API
Clojure
2
star
74

ep33testcljs

Testing ClojureScript with multiple backends
Clojure
2
star
75

elpa

Lambda Island Emacs Lisp Package Archive
Emacs Lisp
2
star
76

datalog-benchmarks

Clojure
2
star
77

kaocha-doctest

Doctest test type for Kaocha
Clojure
1
star
78

morf

Clojure
1
star
79

kaocha-midje

Midje integration for Kaocha
Clojure
1
star
80

land-of-regal

Playground for Regal
Clojure
1
star
81

compobook

An example Compojure app
Clojure
1
star
82

ep41-react-components-reagent

Demo code from Episode 41, using React Components from Reagent
Clojure
1
star
83

dotenv

Clojure
1
star
84

repl-tools

Clojure
1
star
85

li45_polymorphism

Code for Lambda Island episode 45 and 46 about Polymorphism
Clojure
1
star
86

rolodex

Clojure
1
star
87

laoban

Clojure
1
star
88

cookie-cutter

Auto-generate Clojure test namespaces in bulk.
Clojure
1
star
89

shellutils

Globbing and other shell/file utils
Clojure
1
star
90

kaocha-cljs2-demo

Example setups for kaocha-cljs2. WIP
Clojure
1
star
91

kaocha-demo

Clojure
1
star
92

kaocha-nauseam

Example project with a large (artificial) test suite
Clojure
1
star
93

li39-integrant

Accompanying code for Lambda Island episode 38 about Integrant
Clojure
1
star
94

webbing

Clojure
1
star
95

slack-backfill

Save Slack history to JSON files
Clojure
1
star
96

janus

Parser for Changelog files
Clojure
1
star
97

xdemo

Demo of xforms/redux/kixi.stats
Clojure
1
star
98

ep23deftype

Code for Lambda Island Episode 23, deftype and definterface
Clojure
1
star
99

ep24defrecord

Code for Lambda Island Episode 24, defrecord and defprotocol
Clojure
1
star
100

ep32testing

Code for Lambda Island Episode 32, Introduction to Clojure Testing
Clojure
1
star