使用CLI运行Midje时为何不报告测试成功?
I’ve run into this exact issue before—here’s what’s going on and how to fix it: the problem comes from running tests via a custom -main function, which skips Midje’s built-in logic for generating test summaries. Here are two straightforward solutions:
Solution 1: Use Midje’s Official Runner (Recommended)
Instead of executing your -main function, let Midje handle test execution end-to-end. Update your test command to use Midje’s dedicated runner module:
clj -A:test -m midje.run hello.test
This will automatically discover your tests, run all checks, and output the full summary—including the expected All checks (1) succeeded. message when tests pass, and detailed failure reports when they fail.
Solution 2: Manually Trigger the Summary in Your -main
If you want to keep using your custom -main function, you need to explicitly tell Midje to print the final test summary after running your facts. Update your test/hello/test.clj file like this:
(ns hello.test (:use midje.sweet) (:require [midje.repl :as midje])) (defn -main [] (facts "facts" (fact "fact" 1 => 1)) ;; Force Midje to output the final test summary (midje/print-summary))
Now when you run clj -A:test -m hello.test, you’ll see the success summary appear as expected.
Why This Happens
When you call facts or fact directly in your code, Midje executes the individual checks but doesn’t automatically generate the final summary. That summary logic is part of Midje’s runner (midje.run), which manages the full test lifecycle—from discovery to result reporting. Using a custom -main skips this runner, so you have to manually invoke the summary function to get that final success message.
Your deps.edn configuration is already correct: you’ve properly added the test directory to the classpath via the :test alias, and your Midje version is compatible with Clojure 1.9.
内容的提问来源于stack exchange,提问作者pdoherty926

