views:

196

answers:

3

I have been trying to clean up the naming and organisation conventions of our projects' unit and integration tests. We are using C#, NUnit, Visual Studio and Resharper.

It seems that if there is one best practice for unit test organisation it is that the layout and naming of the test classes and namespaces should mirror those of the code under test. As a consequence the file structure will also be replicated.

Wouldn't it be nice to have a tool that could automatically enforce and help refactor code to conform to these conventions? Does a tool like this exist?

For example, it would be simple for Resharper to recognise that OrderTest is a test fixture for the Order class. It could then ensure that the Order class exists and that it is in the same namespace. If the Order class underwent refactoring and was renamed, the OrderTest class should also be renamed.

+3  A: 

I have often wanted that too. I looked at the Resharper bug tracker and found the enhancement request of this issue. It is scheduled for Resharper 5.0. Here is its description: http://www.jetbrains.net/jira/browse/RSRP-64050.

As for the naming and organization of unit tests, standards are changing quite a bit, especially with some of the bdd styles that are popping up. Here is a good post on that naming style. I think it's best for tools to just let a team adapt and create its own standards. With collective code ownership, there should be just one standard after a while.

Michael Hedgpeth
A: 

Ours are currently Test01, Test02, Test03, etc... It's like a steering wheel in a pirate's pants.

I much prefer, and am switching to, this style of naming:Behavior Driven Development: As Human As Possible

Chris Doggett
A: 

Actually ReSharper 4.5 has naming Styles that will warn you if you don't follow naming conventions you set. Few days ago I blogged about this.

If you are interested, follow this link: http://vkreynin.wordpress.com/2009/04/09/resharper-45-complains-about-my-private-fields/.

Vadim
You are right but I don't think they have the capabilities to solve this issue.
cbp