Reputation: 1188
What is your general rule in naming your unit test methods? I am sure a lot of people out there also wonder about this question. Suppose, a method under test is
public Customer GetCustomerById(int id)
How would you name your unit test methods?
GetCustomerById
?
GetCustomerByIdTest
?
GetCustomerByIdShouldReturnCustomer
?
GetCustomerByIdShoudReturnCustomerWhenItSucceeds
?
GetCustomerByIdShouldReturnNullWhenNotFound
?
Get_Customer_By_Id
?
..and so on and so forth.
Any thoughts? Thanks.
Upvotes: 4
Views: 616
Reputation: 6775
I would suggest to use following format. This helps to know what exactly you are testing by just looking at the test method name.
[UnitOfWork_StateUnderTest_ExpectedBehavior]
GetCustomerById_WithValidId_ReturnsCustomer
GetCustomerById_WithInvalidId_ReturnsNull
This is using Roy Oshrove's suggested naming standard: http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html
Upvotes: 6