是否可以调整clojure.test的输出?

时间:2012-10-08 18:12:05

标签: unit-testing clojure

我有这个测试:

(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[])"]))))

现在我确定这个失败了,我的输出就像

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.

我发现这个相当难以理解。而不是那样,我更喜欢输出:

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

按原样,我只是想弄清楚我在比较什么。

2 个答案:

答案 0 :(得分:10)

clojure.test的报告可通过重新绑定clojure.test/report函数进行配置。这在docs for the namespace中有所描述。将使用一系列事件映射调用您的函数,每个事件映射代表测试运行的某个阶段。有一个在clojure.testhere中生成与JUnit兼容的输出的示例。

答案 1 :(得分:4)

Clojure有几个流行的测试框架,clojure.test(你正在使用)很受欢迎,尽管Midje看起来它的输出更接近你正在寻找的东西。以下是测试失败的示例:

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