Fork me on GitHub
#testing
<
2016-08-16
>
metametadata10:08:00

@abarylko extracting a helper function (`test-get-res-with-pagination`) looks totally OK to me in most cases. This approach only becomes a problem when you have lots of the same deftests which you need to call for another endpoint. E.g. when you also have to test the same behavior not only about paging, but also about authorization, caching and logging. As in: you've written a suite of 50 deftests for customers and now want to reuse the suite for houses. I've encountered such scenario but didn't find a good solution at the time. I extracted a parametrized test-...-contract function with multiple testing clauses in it and called this function within a deftest for each thing I wanted to conform to such contract. The potential drawback is that such test suite will "short-circuit" in case of an exception thrown outside of is clauses. Here's an example of my contract function: https://github.com/metametadata/clj-fakes/blob/71ed5225ebb7974b2a4e70b137effe03388a3d52/test/unit/fake_fn_contract.cljc#L14 And how I reuse it in two places: 1. https://github.com/metametadata/clj-fakes/blob/71ed5225ebb7974b2a4e70b137effe03388a3d52/test/unit/fake.cljc#L17 2. https://github.com/metametadata/clj-fakes/blob/71ed5225ebb7974b2a4e70b137effe03388a3d52/test/unit/recorded_fake.cljc#L35

roberto16:08:35

is there a lein plugin for test reports? Currently the result of a test looks something like this:

Ran 22 tests containing 43 assertions.
2 failures, 1 errors.
Tests failed.

roberto16:08:19

but I’d like to see something like this:

Ran 22 tests containing 43 assertions.
2 failures, 1 errors.
Tests failed.

x.y.z/first-test failed
x.y.w/second-test failed

roberto16:08:40

instead of having to scroll up and find the failing tests. This is cumbersome when there are log statements.

jakemcc16:08:25

@roberto: Not sure if one exists, but you can write your own by supplying your own defmethod for the report multi-method. multi-method: https://github.com/clojure/clojure/blob/master/src/clj/clojure/test.clj#L324 example of changing output: https://github.com/clojure/clojure/blob/master/src/clj/clojure/test/junit.clj

jakemcc16:08:27

@roberto: you would probably need to supply a new :fail and :summary method

abarylko19:08:55

Thanks @metametadata ! I’ll take a look, I was wondering if using a macro to generate the common test cases would be a good idea…...