test-check

bartuka 2020-01-04T16:35:25.001200Z

hi ppl, how do you usually integrate test.check with deftesting or midje?

bartuka 2020-01-04T16:36:03.002100Z

I am slowly building some property-based tests in my code base to learn more about it, but I currently use midjeto my tests and would like to have it more integrated

2020-01-04T17:27:28.003500Z

At worst you can call the quickcheck function and assert that the pass? key (or whatever it's called) is true

2020-01-04T17:28:10.004700Z

defspec is the normal integration point with clojure.test, I have no idea if that's usable with midje

bartuka 2020-01-04T18:42:46.005100Z

I had done this macro to help me... it's working but not ideal

(defmacro check-that [desc n property]
  `(fact ~desc
     (let [check# (tc/quick-check ~n ~property)
           passed# (:result check#)]
       (when-not passed# (clojure.pprint/pprint check#))
       passed# => true)))

bartuka 2020-01-04T18:43:12.005700Z

the message when error occur is not visible in the midje stack trace.. but I still get it.

2020-01-04T18:57:59.006Z

you're checking the wrong return key

2020-01-04T18:58:06.006300Z

exceptions are exactly the edge case where that doesn't work

2020-01-04T18:59:31.007500Z

if you want exceptions reported the way midje would, you can also do something like

(when (and (not (:pass? check#)) (:result check#))
  (throw (:result check#)))

2020-01-04T18:59:49.007900Z

or maybe midje has a less hacky way to do that

bartuka 2020-01-04T19:00:15.008400Z

oh.. didn't know!! thanks

2020-01-04T19:00:33.008700Z

the keys are a bit confusingly named for legacy reasons

2020-01-04T19:01:24.008900Z

but they're described in the docstring at least

bartuka 2020-01-04T19:02:50.009800Z

the :result key is not a boolean? So when an exception happen the result will be a keyword :exception something like that?

2020-01-04T19:03:10.010100Z

no it'll be an actual exception object

2020-01-04T19:03:26.010300Z

:pass? is always a boolean

bartuka 2020-01-04T19:04:28.010900Z

got it! thanks for the hint

1👍
bartuka 2020-01-04T19:05:18.011500Z

just watched your presentation and started to write tests to a utils namespace I have in my current project

bartuka 2020-01-04T19:05:40.012Z

interesting bits already pop out!! some edge cases dealing with dates 😃

bartuka 2020-01-04T19:07:00.013100Z

and a performance issue as well. lol. The prod version of the code took 12secs to run 1000 times.. after some refactor it went down to 2sec. And it still works! I used to slow one to validate the fast impl. (Y)

2020-01-04T19:07:27.013400Z

oh yeah, I love the before-and-after refactoring check

1🦜
2020-01-04T19:08:45.013900Z

"test.check as incentive to make your code faster" is an angle I hadn't considered before 🙂

2020-01-04T19:09:22.014300Z

it's almost the opposite of the TDD people that put high effort into making the tests extremely fast

bartuka 2020-01-04T19:10:34.015300Z

that's true. I stumbled in test.check because I am really studying tests as a whole subject and experimenting it in my project here

bartuka 2020-01-04T19:10:59.015900Z

this subject has people with very very strong opinions hehehe

bartuka 2020-01-04T19:11:43.016600Z

saw some guy arguing that Golang was the standard language for TDD because of the incredible fast feedback you get from your entire suite running in ms

bartuka 2020-01-04T19:11:54.017Z

o.O

2020-01-04T19:12:15.017500Z

¯\(ツ)

bartuka 2020-01-04T19:13:44.018400Z

do you have more material about property-based tests to share? I am looking for something more conceptual about how to spot invariants

bartuka 2020-01-04T19:14:14.019Z

I know it is very context based, but some general concepts must be applicable

2020-01-04T19:14:26.019300Z

there's language-agnostic material on that subject

2020-01-04T19:14:44.019700Z

or rather, any material on that subject regardless of language would be applicable

2020-01-04T19:15:36.020Z

e.g., a quick trip in the googlemobile suggested: https://fsharpforfunandprofit.com/posts/property-based-testing-2/

bartuka 2020-01-04T19:18:09.020500Z

cool, thanks! I will keep my search as well o/

alexmiller 2020-01-04T19:21:59.021100Z

I spent a bit of time trying to talk about this in Clojure Applied, not sure I said anything revolutionary, but perhaps of interest

bartuka 2020-01-04T19:25:20.021900Z

I like when ppl suggest a book and I have it hehe. thanks for pointing out @alexmiller Part III on Practices (Y)

alexmiller 2020-01-04T19:27:48.022200Z

yeah, it's chapter 8

bartuka 2020-01-04T20:10:53.024800Z

gosh, how can I work next monday o.O I just got this error from a test:

There is insufficient memory for the Java Runtime Environment to continue.
 repl_1  | # Native memory allocation (malloc) failed to allocate 312 bytes for AllocateHeap
 repl_1  | # An error report file with more information is saved as:
 repl_1  | # /app/hs_err_pid46.log
It is a simple code to add business days taking into account Brazilian holidays to an java.util.Date. But the generator is creating java.util.Date with any values for min,secs and millis. Then, this happened:
(.equals #inst "1980-02-02T00:01:01.000-00:00" #inst "1980-02-02T01:00:01.000-00:00")

bartuka 2020-01-04T20:11:07.025200Z

it was suppose to be true in the prod code =(

2020-01-04T20:11:38.025700Z

... why?

bartuka 2020-01-04T20:12:29.026500Z

people [me probably] was imagining this code as a Date not DateTime inputs

bartuka 2020-01-04T20:12:45.027Z

but some day this extension happened without proper care rsrs

2020-01-04T20:13:00.027300Z

LocalDate?

bartuka 2020-01-04T20:13:14.027500Z

yes

2020-01-04T20:14:30.028100Z

so many languages/libraries seem to encourage people to think of datetimes as localdates with more resolution, but that's not at all the case

bartuka 2020-01-04T20:15:25.028700Z

yeah, first few minutes and a lot of lessons. This year will be nice. haha

bartuka 2020-01-04T20:16:31.029400Z

and funny enough, we had an example-based tests.. but the java.util.date passed around was all with T01:00:01.000-00:00

bartuka 2020-01-04T20:30:08.030300Z

I edit.. both were the same, year, month and day. But different hour.