简体   繁体   中英

Is it possible to tweak 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 made sure this fails, I get output like

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 fairly unreadable. Rather than that, I would prefer output like:

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

As is, I have troubles just figuring out what I was comparing with what.

clojure.test 's reporting is configurable by rebinding the clojure.test/report function. This is described in the docs for the namespace . Your function will be called with a succession of event maps, each representing some phase of the test run. There's an example of generating JUnit-compatible output in the clojure.test source here .

There are several popular testing frameworks for Clojure, clojure.test (which you are using) is popular though Midje looks like it's output is closer to what you're looking for. Here is an example 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM