This is my response to the 2nd Developer Blog Banter. The question asked is

How do you organise your tests. Do you separate your unit tests, integration tests and UI tests into separate projects? Do you do anything specific to keep track of your tests? What naming conventions do you use? Do you run them before a check in or is that what the build server is for?

Structure

Most of my testing efforts focus on unit testing. I structure it so that I have a unit test project per code project. For example

DavidSolution
/BusinessLogic
/BusinessLogicTests
/MoreCode
/MoreCodeTests
/...

If it is a really small application with only a logic project and a host, then I will usually roll the tests into a single unit test project.

Naming conventions old

My naming conventions of my unit tests have change from project to project. On my last project I used to put all unit tests for a class into a single test class and do name each test something similar to this TheBusinessLogicCreatePersonMethodShouldReturnANewPerson()

However I found the names too long to quickly see what broke. Having them all the tests in a single TestClass combined with the tests being sorted alphabetically in the test results it would make it really hard to see what area of my code had broken.

Naming conventions new

I was talking to Damian Maclennen who showed me an example of how he is setting up his BDD tests. I took his approach of using extension methods and bastardised it into my new naming convention.

In my unit test project, I have a namespace for each logic class I am testing. E.g. Person
DavidProject.BusinessLogicTests.Person

Inside of that namespace I have a TestClass for each method I am testing on that class. I name the test class with the method name and ‘Should’ appened to the end, e.g.
CreatePersonShould

Finally I have all of my tests for that method inside that class. This brings it out so my tests look like

namespace DavidProject.BusinessLogicTests.Person
{
    [TestClass]
    public class CreatePersonShould
    {
        [TestMethod]
        public void NotCrashWhenPassedNull()
        {
        ....
        }
    }
}

When I run my tests in Resharper, I will then see all of the tests nested nicely by class name, and then all of the tests for that method.

When do I run them?

Whenever I change a big chunk of code. I don’t practice TDD, I usually create tests and code together as I write (or slightly after I have finished writing the code).

I haven’t set it up to run them on the build server on my current project, that is something I’ll get running this week.

Other forms of testing

I don’t do automated UI tests as I feel the effort required to script them isn’t worth the pay off as they are very brittle.

By David Burela