Can I customize the output of clojure.test?

I have this test:

(ns opengltuts.core-test (:use clojure.test opengltuts.util) (:import (org.lwjgl.opengl GL11 GL12 GL13 GL14 GL15 GL20 GL21 GL30 GL31 GL32 GL33))) (def gl-classes [GL11 GL12 GL13 GL14 GL15 GL20 GL21 GL30 GL31 GL32 GL33]) (deftest find-method-test (testing "find-method finds method in single class" (is (= (find-method "toString" Object) ["public java.lang.String java.lang.Object.toString()"]))) (testing "find-method finds all methods in list of classes" (is (= (apply find-method "glShaderSource" gl-classes) (comment "Omitted a 'p' to trigger failure") ["ublic static void org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])"])))) 

Now I have made sure that this fails, I get the output, for example

 lein test opengltuts.core-test FAIL in (find-method-test) (core_test.clj:14) find-method finds all methods in list of classes expected: (= (apply find-method "glShaderSource" gl-classes) ["ublic static void org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])"]) actual: (not (= ("public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])") ["ublic static void org.lwjgl.opengl.GL20.glShaderSource(int,java.nio.ByteBuffer)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence)" "public static void org.lwjgl.opengl.GL20.glShaderSource(int,java.lang.CharSequence[])"])) Ran 1 tests containing 2 assertions. 1 failures, 0 errors. Tests failed. 

I find this pretty impenetrable. Instead, I would prefer the output, for example:

 <all that info stuff, like the name of the test> Expected: [something] Got: [something-else] 

As is, I have problems just figuring out what I compared to that.

+7
source share
2 answers

There are several popular test frameworks for Clojure, clojure.test (which you use), although Midje seems like the solution is closer to what you are looking for. The following is an example of a test failure:

 FAIL at (t_core.clj:13) Expected: "I am a test file fact" Actual: 3 

https://github.com/marick/Midje/wiki/Migrating-from-clojure.test

+4
source

clojure.test reporting is configured by restoring the function clojure.test/report . This is described in docs for the namespace . Your function will be called with a sequence of event cards, each of which represents some phase of the test run. Here's an example of creating a JUnit-compatible output in the clojure.test source here .

+9
source

All Articles