Giter VIP home page Giter VIP logo

cljunit's Introduction

cljunit

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

Usage

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 {
	@Override
	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 {
	@Override
	public List<String> namespaces() {
		return Arrays.asList(new String[] {
			"mikera.vectorz.test-core",
			"mikera.vectorz.test-matrix"			
		});
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.