- Create a new solution
- Create under that solution two projects: YourApplication and YourApplicationTest
- In this setup we'll write our unit tests in a separate project (YourApplicationTest). Whether the unit tests are written in the same project (pro: code can test itself, con: double the namespace filled up) is a matter of personal preference.
- In YourApplicationTest do the following:
- RightClick the project in the solution explorer and choose 'Manage NuGet Packages'
- Using the NuGet Package Manager:
- Install NUnit version 2.6.4(!!)
- Install NUnitTestAdapter 2.0.0
- If all went well then it's now possible to write unit tests in the YourApplicationTest project. The problem remaining is that we want to write the unit tests for YourApplication in YourApplicationTest and encapsulation will prevent that out of hand. Therefore
- In YourApplication do the following:
- In assemblyinfo.cs add:
- [assembly:InternalsVisibleTo("YourApplicationTest")]
- In classes which contain unit tests in YourApplicationTest add:
- using YourApplication
Done :-)
Geen opmerkingen:
Een reactie posten