Expectations

a minimalist's unit testing framework

This project is maintained by jaycfields

expectations

adding signal, removing noise

Installing

The easiest way to use expectations in your own projects is via Leiningen. Add the following dependency to your project.clj file:

[expectations "2.0.9"]

note: expectations can go in a dev profile in project.clj to avoid pushing the dependency downstream.

To build expectations from source, run the following commands:

$ lein deps
$ lein jar

Getting Started With Leiningen

Add simple_test.clj to your test directory

(ns simple-test
  (:use expectations))

(expect nil? nil)

expectations integrates with Leiningen via lein-expectations.

Usage for lein-expectations:

Declare lein-expectations in project.clj:

:plugins [[lein-expectations "0.0.7"]]

To run all your tests:

$ lein expectations

You can also use lein-autoexpect to automatically run expectations when your Clojure source changes.

Getting Started With Emacs

Add simple_test.clj to your test directory

(ns simple-test
  (:use expectations))

(expect nil? nil)

Follow the directions available on expectations-mode

Getting Started With IntelliJ

Create a directory and mark it as a Test Source. more info For example, you can create proj/test/java and mark 'java' as a test source. Then you also create proj/test/clojure and also mark that as a test source directory.

If you want all of your tests to run in JUnit all you need to do is implement ExpectationsTestRunner.TestSource. The following example is what I use to run all the tests in expectations with JUnit.

import expectations.junit.ExpectationsTestRunner;
import org.junit.runner.RunWith;

@RunWith(expectations.junit.ExpectationsTestRunner.class)
public class ClojureTests implements ExpectationsTestRunner.TestSource{

    public String testPath() {
        // return the path to your root test dir here
        return "test/root/dir";
    }
}

Create ClojureTests.java in your proj/test/java directory. Next you can create sample-test in proj/test/clojure.

(ns simple-test
  (:use expectations))

(expect nil? nil)

That's it, you can now use the JUnit Test Runner built into IntelliJ to execute your expectations.

Getting Started Otherwise

By default the tests run on JVM shutdown, so all you need to do is run your clj file and you should see the expectations output.

You can test that everything is working correctly by using expectations in a simple test.

(ns simple.test
  (:use expectations))

(expect nil? nil)

(assuming you've put your dependencies in a (relatively pathed) lib dir)

Running your clj should be similar to:

$ java -cp "lib/*" clojure.main -i /path/to/your/simple/test.clj

At this point you should see output similar to:

Ran 1 tests containing 1 assertions in 5 msecs
0 failures, 0 errors.

You can run the examples in expectations with:

$ java -cp "lib/*" clojure.main -i /path/to/expectations/test/clojure/success/success_examples.clj