Lazycoder

10Apr/082

Where do you put your unit tests?

 

Unit Test Projects or Not? – Fear and Loathing

 

I was thinking about this too. If I ever get to write code in a language released in the 21st century, where would I put the unit tests?

My first thought was to put them in the same code file, with the tests right next to the code they are testing. Then you can test internal/private stuff without having to use any attributes or special settings. But that might decrease the readability of the code. You could wrap them  up and hide the tests in regions, but the tests still get include in the assembly unless you wrap them with a bunch of #ifs. So that’s not quite ideal.

 

Maybe there needs to be a change to the languages? Maybe a pre-processor automagically strips out your tests when you compile in a non-debug configuration?

Filed under: General Leave a comment
  • Duncan Smart

    In a separate file, but as close to the code as possible, wrapped in a #if TESTS or #if DEBUG using this VS macro: http://blog.dotsmart.net/2008/03/04/tests-behind-tests-as-code-behind-files/

    A separate project just doesn’t make any sense to me.

  • http://computeristsolutions.com josh

    I’m of the opinion of using a separate project because I don’t want ANY extra stuff or references in my production code. It could be silliness, but that’s what works for me.