Re:Stop requiring only one assertion per unit test: Multiple...
by superjan on Saturday November 05, 2022 @08:32AM
(#33480804)
Is this shared somewhere?
[ Parent
| on HN ]
Re:Stop requiring only one assertion per unit test: Multiple...
by torginus on Saturday November 05, 2022 @08:49AM
(#33480913)
Nah, it was some corporate project. But if you are interested, I could rewrite it. It would be a fun weekend project.
Re:Stop requiring only one assertion per unit test: Multiple...
by mattmanser on Saturday November 05, 2022 @09:27AM
(#33481252)
It's also worth figuring out for yourself though! They're suprisingly easy to use (look up Expression<>).
It's incredibly useful once you know how, and encourages you to stop using reflection, passing magic strings as arguments, or having to use nameof().
Re:Stop requiring only one assertion per unit test: Multiple...
by mananaysiempre on Saturday November 05, 2022 @09:30AM
(#33481282)
FWIW, in Python, this is pytest’s entire thing (although it ends up grovelling into bytecode to achieve that).
Re:Stop requiring only one assertion per unit test: Multiple...
by throwaway6977 on Saturday November 05, 2022 @09:34AM
(#33481311)
Not quite the same, but available on nuget- 'fluentAssertions' gives you something akin to this. I've had decent success with having our juniors use it vs less verbose assertion libraries. I don't know about evaluating individual expressions in a line separately, but it does give you clean syntax and similar error messages that are very readable-
"GetProductPage().GetProductPrice().Should().Be().LessThan(...)"
Re:Stop requiring only one assertion per unit test: Multiple...
by opminion on Saturday November 05, 2022 @10:00AM
(#33481546)
https://stackoverflow.com/a/700325
to write out the internal structure of a LambdaExpression.
If you just want the assignments then it's simpler:
Add to the Evaluate method a test for MemberExpression and then:
The variable name is:
((MemberExpression)expr).Member.Name
The value is:
Expression.Lambda(expr).Compile().DynamicInvoke()