Unit Test Method Names

January 4, 2008

 I would like to share some experience with unit test projects in Visual Studio. When you run the unit tests  the method name is what is displayed in the result screen.

Take a look at this screen shot of my current project and you will know what I’m talking about:

unit test method names

Because the test name is what the unit tests method name is, it makes sense to create very long and descriptive method names. You will not be using these method names in code or anything the very long names wont turn into a readability problem. You are just running these tests to see the beautiful green ticks.

Important Note: One of the Failed unit tests that aren’t visible in the screen shot threw an exception of “Failed Can_Create_BackEnd_User Tests Test method OricaMiningServices.Tests.UserManagerTest.Can_Create_BackEnd_User threw exception:  System.NotSupportedException: Specified method is not supported.. ” The exception is being thrown by the create method of the asp.net Membership class. The exception when stepping through the debugger is “Password is not strong enough” but the error message that appears in the test result window is the previous copy pasted error. Huh? What gives. When I step through the web application I can a password not strong enough error. When the unit test tries to access the method I get a different exception?! After 5 minutes of scratching my head it hit me. (Well, this is my guess anyway) There is no HTTP context for the unit test to run on, and there for none of the asp.net membership provider stuff can possibly work. For example, who are you authenticating? The Unit Test? It’s no me (Robert) that is running the application it’s visual studio’s unit test project. Anyway in my opinion this is a bug and should be fixed because it makes unit testing the whole user security layer slightly more complex.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: