Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete expectations should throw exception #277

Open
daniel-rusu opened this issue Jan 2, 2023 · 0 comments
Open

Incomplete expectations should throw exception #277

daniel-rusu opened this issue Jan 2, 2023 · 0 comments

Comments

@daniel-rusu
Copy link
Contributor

daniel-rusu commented Jan 2, 2023

I just switched to Strikt and love it so far. However, I made the mistake of forgetting to validate values several times especially when tired or distracted because it reads naturally:

expectThat(person.isMarried())

instead of
expectThat(person.isMarried()).isTrue()

so no actual validation is performed even though it reads like it would validate it so it's really easy to miss.

Similarly
expectThat(person.age > 18) // instead of using .isGreaterThan(18)
etc.

Would it be possible to catch this flaw and throw an exception at runtime? Perhaps register the Assertion.Builder when creating it with expectThat(...) and capture whether any assertions were performed on it with a flag and throw an exception if it wasn't used by the end of the test.

An alternative approach would be to treat a missing validation as an implicit isTrue().

I would prefer the first approach of throwing an exception as that would nudge me towards writing more idiomatic tests but the second approach is better than skipping validations so either approach would be a large improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant