4

I'm brand new to Unit Testing, fresh out of college, and suddenly responsible for developing and maintaining a fairly large application by myself. The previous developer (who just left the company) included NUnit with the project references, wrote a few empty test fixtures at the bottom of a couple classes, and never did anything else with it.

I'm afraid if I don't start writing unit tests now, while I'm refactoring and learning the system, I'll never get them done, but I'm having trouble understanding how to properly set up my test project.

I was told that I should keep my test project as a separate Class Library within the same solution, so I've made an OurApplication.Test Library project. I don't know how I reference the project that I'll be testing within it, though.

Guides online say to point it to my main project's .DLL... but there isn't one. Our project is a standalone application that doesn't generate a dll, and I'm not sure what I'm supposed to do in this case.

Any advice on what's wrong here, or pointers to more comprehensive guides would be greatly appreciated. I'd like to get this done the right way, and as soon as I can.

KChaloux
  • 3,918
  • 6
  • 37
  • 52
  • 2
    The right thing would be to split the monolithic exe into at least an exe and a dll. The exe would just have to code to get things rolling maybe a Main function. The exe and the tests can both refer to (use) the production dll. However as you said 'it has been a while' - splitting may be a tough ask. So the pragmatic thing to do now (without causing too many ripples in the pond) would be to just refer to the .exe project from your test dll (It wasn't possible earlier but is now.) Get it under test and then get back to splitting with confidence later. – Gishu Sep 25 '12 at 04:42
  • @Gishu Thanks for the advice, and understanding that splitting it up at this point in time is way beyond the scope of what I can do (I'm so far off track from my original goals as it is), but I'll definitely keep it in mind as things start to come together. – KChaloux Sep 25 '12 at 12:20
  • the benefit of adding unit testing now is that if you think in terms of eventually splitting the project into class libraries then your tests will act as a safety net when you come to make the jump! – Paul D'Ambra Sep 25 '12 at 16:50

2 Answers2

5

If you're using Visual Studio you can add references to Projects within the solution as here referencing a console application from a test project

enter image description here

Paul D'Ambra
  • 7,629
  • 3
  • 51
  • 96
  • +1 for the handy guide and attached image. I'll give it a shot when I get back to work tomorrow, and then you'll probably get the accepted answer. – KChaloux Sep 25 '12 at 01:53
4

Ideally it is best to separate your applications into separate dlls which based of functionalities , I.e. separating the solution into modules represented by projects of type class libraries. This will make it simpler to test these dlls separately. I usually have separate test project for each module (projects).

Having said that you can add a .exe project as a reference to your nun it project and get access to all namespaces and classes to test, though not best practice for maintainable code.

NiladriBose
  • 1,849
  • 2
  • 16
  • 31
  • +1 for the sound advice. Unfortunately this is 5 years of development already done by another guy that I was just tasked with in the last few months :p – KChaloux Sep 25 '12 at 01:52