I like to create my test methods like:
Should_not_allow_negative_number_in_value()
But it’s pretty boring to keep typing _ every time, and it also has always the same signature…
so… anybody knows to make it faster??
thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Something that might automate (not at all, but a little more if you use this naming notation) this process:
I usually name my tests like this:
MethodToTest_State_ExpectedBehaviorExample:
You can install ReSharper, and create a new Live Template like:
and asign a shortcut like tst.
Now, everytime you want to add a new method, you just need to start writing tst and press
TABtwo times, and it will create that method for you, placing the caret on theMethodname. After you pressEnter, the caret will move to the place you write theStatename, then for theExpected, and then it will be placed where says$END$.Edit:
That could be helpful too if you name all your tests with
_Should. Something like:ConvertToInt32_NullValue_ShouldReturnTrueThen you can modify your template to:
You could even try to group your naming conventions into a few groups, and create a snippet/template for each of them.
Edit 2:
More about this test naming convention: Naming Standards For Unit Tests, by Roy Osherove, author of The Art Of Unit Testing.