testing

Testing tools, testing philosophy & methodology...
2017-03-18T16:29:03.265139Z

Hi! does anyone know where to find a good example on how to use clojure.test/report to build custom assertion functions? (I understand that’s the way to go rather than wrapping clojure.test/is)

nberger 2017-03-18T18:09:58.738034Z

@facundo: the way to do that is by defining new methods of the assert-expr multimethod. From the clojure.test ns dictating:

EXTENDING TEST-IS (ADVANCED)
You can extend the behavior of the \"is\" macro by defining new
   methods for the \"assert-expr\" multimethod.  These methods are
   called during expansion of the \"is\" macro, so they should return
   quoted forms to be evaluated.
I don't have an example at hand

nberger 2017-03-18T18:11:05.743333Z

c.t/report is just for reporting, not for assertions

nberger 2017-03-18T18:11:47.746344Z

And nice to see you around btw :)

👍 1
nberger 2017-03-18T18:28:13.821278Z

Here you can find some examples from clojure.test itself: https://github.com/clojure/clojure/blob/master/src/clj/clojure/test.clj#L491

2017-03-18T18:49:50.918935Z

thanks for the answer @nberger ! that code was useful, but I figure I wasn’t accurate when I said assertion functions

2017-03-18T18:50:33.922722Z

I actually want to create a function to use instead of is rather that something to call inside is

2017-03-18T18:52:29.931427Z

I already have a working version of what I want, but wrapping is calls. It goes something like this:

(deftest application-crud
  (testing "create a new app"
    (-> (POST "/api/v1/management/applications" {:name "my-app"})
        (expect :status 201
                :body {:name “my-app”}))))

2017-03-18T18:53:23.935440Z

the expect function checks the response of the request against the parameters given (:status, :body, etc)

2017-03-18T18:53:54.937746Z

I already implemented expect wrapping calls to is, which works well enough

2017-03-18T18:55:37.946224Z

the one thing that I’m loosing is the line numbers, which point to the expect definition rather than the failing test. I imagine I could make a macro or something to preserve the line numbers