testing

Testing tools, testing philosophy & methodology...
atrizzain 2020-08-28T14:57:00.003800Z

I’m currently using midje to test a particular function. This function invokes the meta function. I am trying to mock out the results of this meta function call but when I run my test I get a StackOverflowError . I just want to double check if mocking meta is a bad idea and I need to figure something else out or if I should keep at it.

practicalli-john 2020-08-28T15:24:39.003900Z

I may not be understanding your question, but not sure what value there is in mocking or testing meta or any other core function. Its not clear if your function is just wrapping meta, which would seem strange. I assume the function must be doing more than that, the implementation should not matter. Without seeing the code it sounds like the tests are too low level.

practicalli-john 2020-08-28T15:25:50.004100Z

I have some basic examples here http://practicalli.github.io/clojure/testing/unit-testing/writing-unit-tests.html

atrizzain 2020-08-28T15:36:05.004300Z

Here is my function I’m testing:

(defn v1-search
  ([{:keys [session-id return-custom-attributes] :as params} doc-type]
   (let [query (psq/modify-with-algorithm params (psq/get-query (psq/update-params params doc-type)))
         es-req (es/spandex-request query (es-index doc-type) session-id)]
     (-> es-req
         (es/invoke-spandex)
         (rsp-trm/transform-response (meta query)
                                     es-req
                                     (tc/transform-item
                                      (get-response-fields doc-type)
                                      return-custom-attributes))))))
And this is what I’m trying to do to test it:
(fact "v1-search invokes a search and response is handled correctly"
    (sut/v1-search [] --doc-type--) => expected-response
    (provided (spdx/request --mock-client-- expected-spdx-request-v1) => response
              (psq/update-params [] --doc-type--) => --updated-params--
              (psq/get-query --updated-params--) => --query--
              (psq/modify-with-algorithm [] --query--) => --query-with-alg--
              (c/es-index --doc-type--) => --index-config--
              (es/spandex-request --query-with-alg-- --index-config-- nil) => expected-spdx-request-v1
              (#'sut/get-response-fields --doc-type--) => response-fields
              (meta --query-with-alg--) => {:algorithm "n-gram"}))
I don’t really care what query is so I’m just trying to mock out the value given by (meta query) Maybe I’m just trying to shortcut too much and shouldn’t be using a meta-constant for query

practicalli-john 2020-08-28T17:00:37.004500Z

I am afraid I dont understand the midge code. I can take a look over the weekend, but dont have any ideas at the moment

atrizzain 2020-08-28T17:39:13.004700Z

No problem. I ended up figuring out mock out other stuff without having to deal with (meta) and I think it ended up being a lot cleaner. Thanks for taking a look!