简体   繁体   中英

Testing a simple function call with clojure.test

I'm just starting to play with Clojure and am having difficulty with something basic. I want to just test a simple function that does 1 + 1.

Here's core.clj

(ns core)

(defn run []
  (+ 1 1))

Here's the test, core-test.clj

(ns core-test
  (:require [clojure.test :refer :all]
            [core :refer :all]))

(deftest a-test
  (testing "Core"
    (is (= 2 run))))

Here's the result

lein test core-test

lein test :only core-test/a-test

FAIL in (a-test) (core_test.clj:7)
Core
expected: (= 2 run)
  actual: (not (= 2 #object[core$run 0x12f8b1d8 "core$run@12f8b1d8"]))

Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
Tests failed.

You are not calling run . Right now you are comparing 2 with the function. Use (= 2 (run)) .

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