robfletcher / strikt

An assertion library for Kotlin
https://strikt.io/
Apache License 2.0
558 stars 61 forks source link

detect expectations that don't match something #70

Open christophsturm opened 6 years ago

christophsturm commented 6 years ago

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.

schoepke commented 6 years ago

+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 ...

robfletcher commented 6 years ago

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.

christophsturm commented 6 years ago

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.