Replies: 1 comment 3 replies
-
In general we follow the https://csharpcodingguidelines.com. We also planned to capture certain design decisions and conventions in #1340
There's no simple rule here. But every relationship has two aspects: the role and the type. If the type is clear from the statement or really not important (which is subjective), use
We've always done that. But recently, I started to think that this may be overkill. If the test throws unexpectedly, the test would fail anyway.
In general I prefer to declare the subject explicitly, but maybe we're being overzealous sometimes.
I have no specific preference here. I just rely on the
Same here. Just stay under 130 characters. |
Beta Was this translation helpful? Give feedback.
-
Writing 56 StreamAssertions tests and going through the 364 TypeAssertions tests, I try to get consistent code layout that fits the project.
But not very surprisingly, with 4762 tests by several authors, there is no real consistency.
I tend to go where I find a good sample to copy, and try to stick with that. But this could make things worse as I might replicate a bad example.
But for me it would be nice if there was a more "official" guide how you would like to see methods to be structured.
Of course, this comes into the territory of taste, but as maintainers, you can set some guardrails so it's easier to contribute.
I can imagine the current rules might have changed over time, or that there is just a relaxed attitude.
Some things I see implemented differently:
Variable declarations
Explicit vs.
var
My preference is to
var
everything, I see there are sometimes SA/CA suggestions.I think
MemberInfo memberInfo =
does not add any value overvar memberInfo =
other then filling more space in my IDE.using
var
also prevents the IDE from suggesting this:Inline A/A/A
I came across this example:
I rather split it, put the act in a
Action
and test explicitly for not throwing an exception.Arrange: Explicit variables vs. inline values
I see a difference in arranging the test.
Very explicit declaration of every parameter
Subject in arrange, values inline
I'm not really seeing a value to declare the values of the method separately. Again it takes up screen estate and they are never used for anything else. So my preference is the second one.
Act: Action lambdas
These are written in many variations.
single line
break after arrow
wrap everyting
Create a straircase
For efficient screen use, I would try to keep it on one line, or as much as to the left as possible
Should()
statement -> single lineTaking the last example
It's also an option to always newline after the arrow for consitency.
Assertions
Assertions follow some unwritten rules pretty much al over the place
[Not]Throw
indented linesBeta Was this translation helpful? Give feedback.
All reactions