Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to Unit Testing

I would like to know how to implement unit testing in an existing (quite large) application using visual studio 2008 (.net 2.0).

I understand that developing unit tests for the existing/legacy code is not realistic but I would like to have tests for code moving forward.

I have found plenty of examples on how to write tests for code but nothing on how to set it up from scratch on an existing project, and how to integrate it into the development cycle.

like image 775
CodeKiwi Avatar asked Feb 24 '09 08:02

CodeKiwi


1 Answers

Simple approach:

  • Pick one of unit test frameworks (Nunit, MbUnit, Xunit, VS unit test framework, ...)
  • Add project for unit tests in your solution (for example UnitTests).
  • Start writing tests.

For easier organization, create at least one namespace for each project in solution, for example UnitTest.Project1, UnitTests.Project2, ... Depending on size of projects, add more levels to namespace.

This way test project is part of solution. If you use some continuous integration tool, then tests can be automatically executed on each commit to source code repository.

Edit:
Regarding comment on MS Unit Test Framework problem with creating unit tests, there is know problem: "Create unit test" wizard does not work. It looks that there are unsupported types of projects that prevent unit test wizard from working correctly. I just tried with one solution that have one F# and several C# projects. I added unit testing project and tried to add tests. Test wizard had problems until I unloaded F# project. Then everything worked fine.

like image 181
zendar Avatar answered Nov 08 '22 02:11

zendar