JUnit test integration for Clojure
Java Clojure
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



JUnit test integration for Clojure.

The purpose of cljunit is to provide a convenient way to write JUnit tests that test Clojure namespaces. This is very useful if, for example, you want to test Clojure code within a Java IDE like Eclipse that has integrated JUnit testing facilities.

Build Status


Include cljunit as a dependency from clojars:

Clojars Project

Then you should extend one of the cljunit classes to create a JUnit test suite to test your Clojure files.

And that's it: you should now have your Clojure tests nicely wrapped up in JUnit test suites. These have been tested to work in the following situations:

  • Running JUnit tests with Eclipse (Run / Run As... / JUnit Test)
  • Running JUnit tests with Maven (you don't even need the clojure-maven-plugin since the regular Maven configuration will automatically run JUnit tests)

Examples below:

Testing all Clojure namespaces:

This is the simplest solution that works for most projects. Just be warned: it will run every Clojure test on the classpath. Which might be a lot if your imported libraries have a lot of tests in them.

import mikera.cljunit.ClojureTest;

public class ClojureTests extends ClojureTest {
	// automatically test all Clojure namespaces in classpath

Testing all Clojure namespaces with a given prefix:

import mikera.cljunit.ClojureTest;

public class ClojureTests extends ClojureTest {
	// filter namespaces with the given prefix
	@Override public String filter() {
	    return "com.mycompany";

Testing a specific namespace:

import mikera.cljunit.NamespaceTest;

public class MyNamespaceTest extends NamespaceTest {
	public String namespace() {
		return "my.clojure.namespace";

Testing a specific subset of Clojure namespaces

Working example from vectorz-clj

import mikera.cljunit.ClojureTest;

public class ClojureTests extends ClojureTest {
	public List<String> namespaces() {
		return Arrays.asList(new String[] {