You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been looking for information on if there is an official standard on how to name xUnit tests for contributions.
The most information I have been able to find under the engineering guidelines are:
Unit test method names must be descriptive about what is being tested, under what conditions, and what the expectations are. Pascal casing and underscores can be used to improve readability.
One thing I noticed is there is a discrepancy about the order of including these in the tests I have come across in the repository.
Many of the older unit tests use the pattern <method>-<input>-<expected result> similar to:
public void Add_EmptyString_ReturnsZero()
Many of the newer unit tests use the pattern <method>-<expected result>-<input> similar to:
public void Add_ReturnsZero_WithEmptyString()
Please bear with me that these are simplistic examples, but I think it gets the idea across.
Is there a current preferred structure? It seems that the general pattern has moved from the first to the second looking at recent changes. Both contain the information from the standard, but the second seems to be more readable as a a sentence, and therefore perhaps more understandable. In many places there seem to be a mix of both.
I don't have a particular preference either way, just looking for if there is any official guidance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I have been looking for information on if there is an official standard on how to name xUnit tests for contributions.
The most information I have been able to find under the engineering guidelines are:
One thing I noticed is there is a discrepancy about the order of including these in the tests I have come across in the repository.
Many of the older unit tests use the pattern
<method>-<input>-<expected result>
similar to:public void Add_EmptyString_ReturnsZero()
Many of the newer unit tests use the pattern
<method>-<expected result>-<input>
similar to:public void Add_ReturnsZero_WithEmptyString()
Please bear with me that these are simplistic examples, but I think it gets the idea across.
Is there a current preferred structure? It seems that the general pattern has moved from the first to the second looking at recent changes. Both contain the information from the standard, but the second seems to be more readable as a a sentence, and therefore perhaps more understandable. In many places there seem to be a mix of both.
I don't have a particular preference either way, just looking for if there is any official guidance.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions