I have inherited a reasonable sized ASP.net solution that has no automated tests. The solution seems to include all of the source/pages in one solution with no name-spacing and no separation of tiers, so there are direct SQL calls within code behind files etc.
Before making changes to this site I would like to add some unit tests, preferably using nunit as I am familiar with the Xunit model, to give me some confidence that I have not broken anything. I do not have much .net experience, and particularly I am not sure about when to use projects vs solutions etc, although I am comfortable with the basic syntax etc of C#.
What is the recommended method of adding units tests to a solution? Should I create a separate Solution/Project for the tests and then add references to appropriate elements of the existing solution, or should I create a separate project within the existing solution to house the test suite.
I am really looking for the pros and cons of both approaches, or indeed another method altogether. What are peoples experiences of the best way to achieve this.
I’m not sure you can start with Unit tests. Remembering that the first rule is “Don’t break what works”, I would suggest starting with some integration or regression tests using something like WatiN or Selenium. Both of these frameworks can run the integration tests from unit test frameworks such as NUnit. Telerik do one as well but it’s not free and I haven’t used it.
Once you have that in place, you can start the process of moving code into layers with the knowledge that you’re not breaking the website. This is then a good time to introduce unit tests.
This I would do by having one project that houses all of the unit tests, with references to the projects that contain the classes you are testing. I believe it’s also good practice to separate your tiers into projects.