├── .gitignore ├── .travis.yml ├── README.md ├── pom.xml └── src ├── main ├── clojure │ └── mikera │ │ └── cljunit │ │ └── core.clj └── java │ └── mikera │ └── cljunit │ ├── Clojure.java │ ├── ClojureRunner.java │ ├── ClojureTest.java │ ├── ClojureTester.java │ ├── NamespaceRunner.java │ ├── NamespaceTest.java │ ├── NamespaceTester.java │ └── VarTester.java └── test ├── clojure └── mikera │ └── cljunit │ ├── cljctest.cljc │ ├── selftest.clj │ ├── test_edge_cases.clj │ └── test_main.clj └── java └── mikera └── cljunit ├── AllClojureTests.java ├── ClojureTests.java ├── CoreNamespaceTest.java └── MikeraTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | /classes 2 | 3 | .project 4 | .settings 5 | .classpath 6 | /target 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | jdk: 4 | - oraclejdk8 5 | - oraclejdk7 6 | - openjdk7 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cljunit 2 | 3 | JUnit test integration for Clojure. 4 | 5 | The purpose of cljunit is to provide a convenient way to write JUnit tests that test Clojure namespaces. This is 6 | very useful if, for example, you want to test Clojure code within a Java IDE like Eclipse that has integrated 7 | JUnit testing facilities. 8 | 9 | [![Build Status](https://secure.travis-ci.org/mikera/cljunit.png?branch=master)](https://travis-ci.org/mikera/cljunit) 10 | 11 | ## Usage 12 | 13 | Include cljunit as a dependency from clojars: 14 | 15 | [![Clojars Project](http://clojars.org/net.mikera/cljunit/latest-version.svg)](http://clojars.org/net.mikera/cljunit) 16 | 17 | Then you should extend one of the cljunit classes to create a JUnit test suite to test your Clojure files. 18 | 19 | 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: 20 | 21 | - Running JUnit tests with Eclipse (Run / Run As... / JUnit Test) 22 | - Running JUnit tests with Maven (you don't even need the `clojure-maven-plugin` since the regular Maven configuration will automatically run JUnit tests) 23 | 24 | Examples below: 25 | 26 | ### Testing all Clojure namespaces: 27 | 28 | 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. 29 | 30 | import mikera.cljunit.ClojureTest; 31 | 32 | public class ClojureTests extends ClojureTest { 33 | // automatically test all Clojure namespaces in classpath 34 | } 35 | 36 | ### Testing all Clojure namespaces with a given prefix: 37 | 38 | import mikera.cljunit.ClojureTest; 39 | 40 | public class ClojureTests extends ClojureTest { 41 | // filter namespaces with the given prefix 42 | @Override public String filter() { 43 | return "com.mycompany"; 44 | } 45 | } 46 | 47 | 48 | 49 | ### Testing a specific namespace: 50 | 51 | import mikera.cljunit.NamespaceTest; 52 | 53 | public class MyNamespaceTest extends NamespaceTest { 54 | @Override 55 | public String namespace() { 56 | return "my.clojure.namespace"; 57 | } 58 | } 59 | 60 | ### Testing a specific subset of Clojure namespaces 61 | 62 | Working example from vectorz-clj 63 | 64 | import mikera.cljunit.ClojureTest; 65 | 66 | public class ClojureTests extends ClojureTest { 67 | @Override 68 | public List namespaces() { 69 | return Arrays.asList(new String[] { 70 | "mikera.vectorz.test-core", 71 | "mikera.vectorz.test-matrix" 72 | }); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | cljunit 4 | net.mikera 5 | 0.7.1-SNAPSHOT 6 | JUnit wrapper for Clojure test code 7 | 8 | 9 | 1.8 10 | 1.8 11 | 1.8 12 | 13 | UTF-8 14 | UTF-8 15 | 16 | 340395AC 17 | true 18 | 19 | 20 | 21 | scm:git:git@github.com:mikera/${project.artifactId}.git 22 | scm:git:git@github.com:mikera/${project.artifactId}.git 23 | scm:git:git@github.com:mikera/${project.artifactId}.git 24 | HEAD 25 | 26 | 27 | 28 | 29 | clojars.org 30 | https://clojars.org/repo 31 | 32 | 33 | 34 | 35 | 36 | clojars.org 37 | Clojars repository 38 | https://clojars.org/repo 39 | 40 | 41 | 42 | 43 | 44 | junit 45 | junit 46 | 4.13.1 47 | 48 | 49 | org.clojure 50 | tools.namespace 51 | 0.3.1 52 | 53 | 54 | org.clojure 55 | java.classpath 56 | 0.3.0 57 | 58 | 59 | org.clojure 60 | clojure 61 | 1.10.1 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.apache.maven.plugins 69 | maven-compiler-plugin 70 | 3.8.1 71 | 72 | 8 73 | 8 74 | 8 75 | 8 76 | -Xlint:deprecation 77 | 78 | 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-javadoc-plugin 83 | 3.1.1 84 | 85 | 86 | attach-javadocs 87 | 88 | jar 89 | 90 | 91 | 92 | 93 | 8 94 | none 95 | -Xdoclint:none 96 | 97 | 98 | 99 | 100 | org.apache.maven.plugins 101 | maven-release-plugin 102 | 2.5.2 103 | 104 | 105 | org.apache.maven.shared 106 | maven-invoker 107 | 2.2 108 | 109 | 110 | 111 | 112 | 113 | org.apache.maven.plugins 114 | maven-gpg-plugin 115 | 1.6 116 | 117 | 118 | sign-artifacts 119 | verify 120 | 121 | sign 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | src/main/clojure 131 | 132 | 133 | src/main/resources 134 | 135 | 136 | 137 | 138 | 139 | src/test/clojure 140 | 141 | 142 | src/test/resources 143 | 144 | 145 | 146 | src/test/java 147 | 148 | -------------------------------------------------------------------------------- /src/main/clojure/mikera/cljunit/core.clj: -------------------------------------------------------------------------------- 1 | (ns mikera.cljunit.core 2 | (:import [org.junit.runner.notification RunNotifier Failure]) 3 | (:import org.junit.runner.Description) 4 | ;; (:require [bultitude.core :as b]) 5 | (:require [clojure.tools.namespace :as ctns]) 6 | (:require [clojure.tools.namespace.find :as ctnf]) 7 | (:require [clojure.java.classpath :as jcp]) 8 | (:use clojure.test)) 9 | 10 | (set! *warn-on-reflection* true) 11 | 12 | ;; intended for binding to capture failures 13 | (def ^:dynamic *reports* nil) 14 | 15 | (defn assertion-message [m] 16 | (str "Assertion failed: {:expected " (:expected m) 17 | " :actual " (:actual m) 18 | (when (:message m) (str " :message " (:message m))) "}" 19 | " <" (:file m) ":" (:line m) ">")) 20 | 21 | (defn truncate-stacktrace [off-top] 22 | (let [st (.getStackTrace (Thread/currentThread)) 23 | stlen (alength st) 24 | st (java.util.Arrays/copyOfRange st (int off-top) stlen)] 25 | st)) 26 | 27 | (def report-fn 28 | (fn [m] 29 | ;;(println m) 30 | (let [m (if (= :fail (:type m)) 31 | (assoc m :stacktrace (truncate-stacktrace 4)) 32 | m)] 33 | (swap! *reports* conj m)))) 34 | 35 | (defn invoke-test [v] 36 | (when-let [t v] ;; (:test (meta v)) 37 | (binding [clojure.test/report report-fn 38 | *reports* (atom [])] 39 | (eval `(~t)) 40 | ;; (println @*reports*) 41 | (doseq [m @*reports*] 42 | (let [type (:type m)] 43 | (cond 44 | (= :pass type) m 45 | (= :fail type) 46 | (let [ex (junit.framework.AssertionFailedError. (assertion-message m))] 47 | ;; (println m) 48 | (.setStackTrace ex (:stacktrace m)) 49 | (throw ex)) 50 | (= :error type) (throw (:actual m)) 51 | :else "OK")))))) 52 | 53 | ;; (deftest failing-test (is (= 2 3))) 54 | (deftest test-in-core 55 | (testing "In Core" 56 | (is (= 1 1)))) 57 | 58 | (defn ns-for-name [name] 59 | (namespace (symbol name))) 60 | 61 | (defn get-test-vars 62 | "Gets the vars in a namespace which represent tests, as defined by :test metadata" 63 | ([ns] 64 | (filter 65 | (fn [v] (:test (meta v))) 66 | (vals (ns-interns ns))))) 67 | 68 | (defn get-test-var-names 69 | "Gets the names of all vars for a given namespace name" 70 | ([ns-name] 71 | (require (symbol ns-name)) 72 | (vec (map 73 | #(str (first %)) 74 | (filter 75 | (fn [[k v]] (:test (meta v))) 76 | (ns-interns (symbol ns-name))))))) 77 | 78 | ;; we need to exclude clojure.parallel, as loading it causes an error if ForkJoin framework not present 79 | (def DEFAULT-EXCLUDES 80 | ["clojure.parallel"]) 81 | 82 | (defn get-namespace-symbols 83 | "Gets the symbols defining namespaces on the classpath, subject to options map. 84 | 85 | Options map may include: 86 | :prefix - only include namespaces which start with the given prefix 87 | :excludes - exclude the list of specified namespaces (exact string names or symbols)" 88 | ([options] 89 | (let [prefix ^String (or (:prefix options) "") 90 | exclude-list (or (:excludes options) DEFAULT-EXCLUDES) 91 | exclude-set (into #{} (map name exclude-list)) 92 | nms (ctnf/find-namespaces (jcp/classpath)) 93 | nms (filter (fn [nsym] 94 | (let [nsname ^String (name nsym)] 95 | (and 96 | (not (exclude-set nsname)) 97 | (.startsWith nsname prefix)))) 98 | nms)] 99 | nms))) 100 | 101 | (defn get-test-namespace-names 102 | "Return namespace names as strings" 103 | ([] 104 | (get-test-namespace-names nil)) 105 | ([options] 106 | (vec 107 | (filter (complement nil?) 108 | (for [nms (get-namespace-symbols options)] 109 | (try 110 | (require nms) ;; might fail during namespace loading 111 | (str nms) 112 | (catch Throwable x 113 | (throw (RuntimeException. (str "Failed to load namespace:" nms) x))))))))) 114 | 115 | 116 | (defn test-results [test-vars] 117 | (vec (map 118 | (fn [var] 119 | (let [t (:test (meta test-var))] 120 | (try 121 | (t) 122 | (catch Throwable e 123 | e))) 124 | test-vars)))) 125 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/Clojure.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import clojure.lang.Keyword; 9 | import clojure.lang.RT; 10 | import clojure.lang.Symbol; 11 | import clojure.lang.Var; 12 | 13 | public class Clojure { 14 | public static final Var REQUIRE=RT.var("clojure.core", "require"); 15 | public static final Var META=RT.var("clojure.core", "meta"); 16 | public static final Keyword TEST_KEY=Keyword.intern("test"); 17 | public static final Keyword PREFIX=Keyword.intern("prefix"); 18 | 19 | static { 20 | require("clojure.test"); 21 | require("mikera.cljunit.core"); 22 | } 23 | 24 | public static final Var GET_TEST_VAR_NAMES=RT.var("mikera.cljunit.core", "get-test-var-names"); 25 | public static final Var GET_TEST_NAMESPACE_NAMES=RT.var("mikera.cljunit.core", "get-test-namespace-names"); 26 | public static final Var INVOKE_TEST=RT.var("mikera.cljunit.core", "invoke-test"); 27 | 28 | @SuppressWarnings("unchecked") 29 | public static Collection getTestVars(String namespace) { 30 | return (Collection) GET_TEST_VAR_NAMES.invoke(namespace); 31 | } 32 | 33 | public static void require(String ns) { 34 | REQUIRE.invoke(Symbol.intern(ns)); 35 | } 36 | 37 | @SuppressWarnings("unchecked") 38 | public static List getNamespaces() { 39 | return (List) GET_TEST_NAMESPACE_NAMES.invoke(); 40 | } 41 | 42 | @SuppressWarnings("unchecked") 43 | public static List getNamespaces(String filter) { 44 | @SuppressWarnings({ "rawtypes"}) 45 | Map hm=new HashMap(); 46 | hm.put(PREFIX, filter); 47 | 48 | return (List) GET_TEST_NAMESPACE_NAMES.invoke(hm); 49 | } 50 | 51 | public static Object invokeTest(Var testVar) { 52 | Object o=INVOKE_TEST.invoke(testVar); 53 | return o; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/ClojureRunner.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | import java.lang.reflect.InvocationTargetException; 3 | import java.util.List; 4 | 5 | import org.junit.runner.Description; 6 | import org.junit.runner.notification.RunNotifier; 7 | import org.junit.runners.ParentRunner; 8 | import org.junit.runners.model.InitializationError; 9 | 10 | public class ClojureRunner extends ParentRunner { 11 | ClojureTester clojureTester; 12 | 13 | public ClojureRunner(Class testClass) throws InitializationError, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { 14 | super(testClass); 15 | 16 | try { 17 | clojureTester=new ClojureTester(testClass.getConstructor().newInstance().namespaces()); 18 | } 19 | catch (NoSuchMethodException e) { 20 | throw new InstantiationException("Unable to get nullary constructor for test class: "+testClass.getCanonicalName()); 21 | } 22 | catch (SecurityException e) { 23 | throw new InitializationError(e); 24 | } 25 | } 26 | 27 | @Override 28 | protected Description describeChild(NamespaceTester vt) { 29 | return vt.getDescription(); 30 | } 31 | 32 | @Override 33 | protected List getChildren() { 34 | return clojureTester.children; 35 | } 36 | 37 | @Override 38 | protected void runChild(NamespaceTester vt, RunNotifier arg1) { 39 | vt.runTest(arg1); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/ClojureTest.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.runner.RunWith; 6 | 7 | @RunWith(ClojureRunner.class) 8 | public abstract class ClojureTest { 9 | 10 | /** 11 | * Returns a list of namespaces for testing. 12 | * 13 | * Subclasses may override this to provide a specific list of namespaces to test. The default is to 14 | * get all namespaces which start with the String returned by the `filter` method in this class. 15 | * 16 | * @return A list of strings giving the names of Clojure namespaces to test, in the form "my.thing.foo" 17 | */ 18 | public List namespaces() { 19 | String filter=filter(); 20 | if (filter==null) { 21 | return Clojure.getNamespaces(); 22 | } 23 | return Clojure.getNamespaces(filter); 24 | } 25 | 26 | /** 27 | * Specifies a prefix filter for namespaces to test, e.g. "my.organisation" 28 | * 29 | * @return A prefix string with which to filter namespaces, or null to match all namespaces. 30 | */ 31 | public String filter() { 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/ClojureTester.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.junit.runner.Description; 7 | import org.junit.runner.notification.RunNotifier; 8 | 9 | class ClojureTester { 10 | private Description desc; 11 | public List namespaces; 12 | 13 | public ArrayList children=new ArrayList(); 14 | 15 | public ClojureTester(List ns) { 16 | this.namespaces=ns; 17 | desc= Description.createSuiteDescription("Clojure Tests"); 18 | 19 | for (String s: namespaces) { 20 | NamespaceTester nt=new NamespaceTester(s); 21 | desc.addChild(nt.getDescription()); 22 | children.add(nt); 23 | } 24 | } 25 | 26 | public Description getDescription() { 27 | return desc; 28 | } 29 | 30 | public void runTest(RunNotifier n) { 31 | n.fireTestStarted(desc); 32 | for (NamespaceTester nt:children) { 33 | nt.runTest(n); 34 | } 35 | n.fireTestFinished(desc); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/NamespaceRunner.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | import java.lang.reflect.InvocationTargetException; 3 | import java.util.List; 4 | 5 | import org.junit.runner.Description; 6 | import org.junit.runner.notification.RunNotifier; 7 | import org.junit.runners.ParentRunner; 8 | import org.junit.runners.model.InitializationError; 9 | 10 | 11 | public class NamespaceRunner extends ParentRunner { 12 | NamespaceTester namespaceTester; 13 | 14 | @SuppressWarnings("deprecation") 15 | public NamespaceRunner(Class testClass) throws InitializationError, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { 16 | super(testClass); 17 | 18 | namespaceTester=new NamespaceTester(testClass.newInstance().namespace()); 19 | } 20 | 21 | @Override 22 | protected Description describeChild(VarTester vt) { 23 | return vt.getDescription(); 24 | } 25 | 26 | @Override 27 | protected List getChildren() { 28 | return namespaceTester.children; 29 | } 30 | 31 | @Override 32 | protected void runChild(VarTester vt, RunNotifier arg1) { 33 | vt.runTest(arg1); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/NamespaceTest.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import org.junit.runner.RunWith; 4 | 5 | @RunWith(NamespaceRunner.class) 6 | public abstract class NamespaceTest { 7 | 8 | public NamespaceTest() { 9 | // nothing, used for default instance 10 | } 11 | 12 | public abstract String namespace(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/NamespaceTester.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | 6 | import org.junit.runner.Description; 7 | import org.junit.runner.notification.RunNotifier; 8 | 9 | class NamespaceTester { 10 | public Description d; 11 | public String namespace; 12 | 13 | public ArrayList children=new ArrayList(); 14 | 15 | public NamespaceTester(String ns) { 16 | this.namespace=ns; 17 | d= Description.createSuiteDescription(namespace); 18 | Collection testVars=Clojure.getTestVars(namespace); 19 | 20 | for (String v:testVars) { 21 | VarTester vt=new VarTester(namespace,v); 22 | d.addChild(vt.getDescription()); 23 | children.add(vt); 24 | } 25 | } 26 | 27 | public Description getDescription() { 28 | return d; 29 | } 30 | 31 | public void runTest(RunNotifier n) { 32 | n.fireTestStarted(d); 33 | for (VarTester vt:children) { 34 | vt.runTest(n); 35 | } 36 | n.fireTestFinished(d); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/mikera/cljunit/VarTester.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import org.junit.runner.Description; 4 | import org.junit.runner.notification.Failure; 5 | import org.junit.runner.notification.RunNotifier; 6 | 7 | import clojure.lang.RT; 8 | import clojure.lang.Var; 9 | 10 | public class VarTester { 11 | Var testVar; 12 | Description desc; 13 | 14 | // private static Keyword FILE= Keyword.intern("file"); 15 | // private static Keyword LINE= Keyword.intern("line"); 16 | 17 | public VarTester(String ns,String name) { 18 | Clojure.require(ns); 19 | testVar=RT.var(ns, name); 20 | desc=Description.createSuiteDescription(ns + '.' + name); 21 | } 22 | 23 | public void runTest(RunNotifier n) { 24 | n.fireTestStarted(getDescription()); 25 | 26 | try { 27 | Clojure.invokeTest(testVar); 28 | n.fireTestFinished(getDescription()); 29 | } catch (Throwable t) { 30 | n.fireTestFailure(new Failure(getDescription(), t)); 31 | } 32 | } 33 | 34 | public Description getDescription() { 35 | return desc; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/clojure/mikera/cljunit/cljctest.cljc: -------------------------------------------------------------------------------- 1 | (ns mikera.cljunit.cljctest 2 | (:use clojure.test)) 3 | 4 | (deftest test1 5 | (is (= 1 1))) 6 | 7 | (deftest test2 8 | (is (= 2 2))) 9 | 10 | 11 | ;; (deftest failing-test (is (= 2 3))) -------------------------------------------------------------------------------- /src/test/clojure/mikera/cljunit/selftest.clj: -------------------------------------------------------------------------------- 1 | (ns mikera.cljunit.selftest 2 | (:use clojure.test)) 3 | 4 | (deftest test1 5 | (is (= 1 1))) 6 | 7 | (deftest test2 8 | (is (= 2 2))) 9 | 10 | 11 | ;; (deftest failing-test (is (= 2 3))) -------------------------------------------------------------------------------- /src/test/clojure/mikera/cljunit/test_edge_cases.clj: -------------------------------------------------------------------------------- 1 | (ns mikera.cljunit.test-edge-cases 2 | (:import [clojure.lang RT Compiler Compiler$C]) 3 | (:use clojure.test)) 4 | 5 | ;; expression info test causes strange edge case because Compiler.LOADER is unbound 6 | 7 | (defn expression-info-internal 8 | [expr] 9 | (let [fn-ast (Compiler/analyze Compiler$C/EXPRESSION expr) 10 | expr-ast (.body (first (.methods fn-ast)))] 11 | (when (.hasJavaClass expr-ast) 12 | {:class (.getJavaClass expr-ast) 13 | :primitive? (.isPrimitive (.getJavaClass expr-ast))}))) 14 | 15 | (defn expression-info 16 | "Uses the Clojure compiler to analyze the given s-expr. Returns 17 | a map with keys :class and :primitive? indicating what the compiler 18 | concluded about the return value of the expression. Returns nil if 19 | no type info can be determined at compile-time. 20 | 21 | Example: (expression-info '(+ (int 5) (float 10))) 22 | Returns: {:class float, :primitive? true}" 23 | [expr] 24 | (expression-info-internal `(fn [] ~expr))) 25 | 26 | (deftest test-expression-info 27 | (testing "expression " 28 | (is (expression-info '(+ 2 3))))) 29 | 30 | -------------------------------------------------------------------------------- /src/test/clojure/mikera/cljunit/test_main.clj: -------------------------------------------------------------------------------- 1 | (ns mikera.cljunit.test-main 2 | (:use clojure.test) 3 | (:use mikera.cljunit.core) 4 | (:require [clojure.tools.namespace :as ctns]) 5 | (:require [clojure.tools.namespace.find :as ctnf]) 6 | (:require [clojure.java.classpath :as jcp])) 7 | 8 | (deftest test-core 9 | (testing "Trivial test" 10 | (is (= 1 1)))) 11 | 12 | (deftest test-find-namespaces 13 | (testing "Namespace lookup using tools.namespace" 14 | (let [nms (ctnf/find-namespaces (jcp/classpath)) 15 | nmset (into #{} (map str nms))] 16 | (is (contains? nmset "mikera.cljunit.core")) 17 | ))) 18 | 19 | (deftest test-namespaces 20 | (testing "Getting all test namespace names" 21 | (let [nms (get-test-namespace-names) 22 | nmset (into #{} nms)] 23 | ;; (println "NMS=" nms) 24 | (is (contains? nmset "mikera.cljunit.core")) 25 | (is (contains? nmset "clojure.core")) 26 | ))) 27 | 28 | (deftest failing-assertion 29 | ;; (is (= 1 2)) 30 | ) 31 | 32 | -------------------------------------------------------------------------------- /src/test/java/mikera/cljunit/AllClojureTests.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | public class AllClojureTests extends ClojureTest { 4 | // test all namespaces by default 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/mikera/cljunit/ClojureTests.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ClojureTests extends ClojureTest { 7 | @Override 8 | public List namespaces() { 9 | ArrayList ns=new ArrayList(); 10 | ns.add("clojure.core"); 11 | ns.add("mikera.cljunit.test-main"); 12 | // ns.add("mikera.cljunit.dummy-nonexistent-namespace"); 13 | return ns; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/mikera/cljunit/CoreNamespaceTest.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | public class CoreNamespaceTest extends NamespaceTest { 4 | 5 | @Override 6 | public String namespace() { 7 | return "mikera.cljunit.core"; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/mikera/cljunit/MikeraTests.java: -------------------------------------------------------------------------------- 1 | package mikera.cljunit; 2 | 3 | public class MikeraTests extends ClojureTest { 4 | 5 | @Override 6 | public String filter() { 7 | return "mikera"; 8 | } 9 | 10 | } 11 | --------------------------------------------------------------------------------