Expectations

a minimalist's unit testing framework

View the Project on GitHub jaycfields/expectations

expectations

where less is more

expectations is a minimalist's testing framework


Credit

Expectations is based on clojure.test. clojure.test is distributed under the Eclipse license, with ownership assigned to Rich Hickey.

Installing

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

[expectations "1.2.1"] ; clojure 1.2
[expectations "1.4.3"] ; clojure 1.3

To build expectations from source, run the following commands:

lein deps
lein jar

Getting Started

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

You can also run expectations using lein if you install lein-expectations. Use lein-autoexpect to automatically run when your Clojure source changes.

You're now ready to start using expectations as you see fit. There's not a ton of syntax; however, you'll probably want to take a quick look at the various ways you can write expectations.

Colorizing

By default, expectations uses ansi escape codes to color output on non-windows environments. expectations also respects a EXPECTATIONS_COLORIZE environment variable - set the var to false if you'd like to turn off colorizing. more info

Success Examples

using 'expect', 'given' and 'expanding'

using 'scenario' and 'stubbing'

Detailed Examples with Discussion

Unit Testing Examples - Part One (Introduction)

Unit Testing Examples - Part Two (Non-Equality)

Unit Testing Examples - Part Three (Using Values)

Unit Testing Examples - Part Four (Testing Double/NaN)

Unit Testing Examples - Part Five (Removing Duplication with 'given')

Unit Testing Examples - Part Six (Wrap Up)

Scenario Testing Examples

Freezing Joda Time

License

Copyright (c) 2010, Jay Fields All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.