Replies: 1 comment 3 replies
-
I'm not sure I get your part about "said method will be executed for every assertion"? Since |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My team has chosen to standardise on FluentAssertions as our assertion library over Shouldly, which we were previously using, as we feel that this project is better maintained. However we have hit something of a stumbling block in our migration, to wit the syntax for testing if exceptions were thrown.
Previously in Shouldly, we were writing code like this:
In FluentAssertions we have to create a
Func
, or use theAwaiting
wrapper which does the same:However technically we should be separating the Act and Assert portions (as suggested in the documentation), so we should really be writing:
But the problem with doing it this way is that the method under test is only executed once
await
ed, i.e. in theAssert
section, which means that said method will be executed for every assertion as opposed to just once. This is completely, utterly wrong - if the method under test is stateful, then executing it multiple times can change its state and thus cause subsequent assertions to fail.In short, I find this an extremely sub-optimal API because it allows you to extremely easily shoot yourself in the foot. Am I correct, or am I just missing something very obvious here?
Beta Was this translation helpful? Give feedback.
All reactions