strikt icon indicating copy to clipboard operation
strikt copied to clipboard

detect expectations that don't match something

Open christophsturm opened this issue 7 years ago • 3 comments

one downside of fluent assertion libs like strikt compared to simple assertEquals(a,b) is that its possible to write assertions that can never fail.

for example this code that tries to assert on a jackson property: expect(offer.has("id"))

it would be great if we could find a way that can potentially find such asserts, possibly at runtime.

christophsturm avatar Aug 13 '18 08:08 christophsturm

+1 from my side, as this happened to me several times (with another fluent lib). It would be nice if strikt could tell the tester that he's shooting his own foot in such cases ...

schoepke avatar Aug 14 '18 09:08 schoepke

Never trust a test you have never seen fail!

Seriously, though. I think it's a good suggestion. I'm not sure how it could be implemented right now. I'd need to somehow detect that no methods were ever called on the Assertion.Builder returned by expect.

robfletcher avatar Aug 15 '18 05:08 robfletcher

it probably would need to be test runner specific. all expectations in a test case need to be registered and then checked afterwards. or you could use a threadlocal where each expect checks that the expect before it had a check.

christophsturm avatar Aug 15 '18 08:08 christophsturm