Follow @RoyOsherove on Twitter

A simple way to unit-test internal classes

Jamie Cansdale (Of Nunit Add-in fame)has been cool enough to share with me a quick way that allows you to test internal classes in your project without referencing the Nunit framework DLL. it's pretty simple, actually.
He simply put the whole NUnit framework attributes and assert class in one cs file.
that's pretty elegant and I'll have to remember that the next time I need this technique.
There are two other ways I can think of to test internal classes:
  1. Use tests inside the project and enclose them inside conditional compilation arguments
  2. Use a separate test project and “link“ to the actual source files you want to use
    1. Right click on project
    2. Add Existing item
    3. in the browse dialog, highlight the file in the tested project
    4. open the small menu on the 'Open“ button
    5. select “Link file“
    6. Note: this only works for classes that have dependencies that are shared between the test and the tested project so it might get a bit too much work if you have large dependencies in your class files.

Microsoft is losing the community battle - against itself

My feed reader of choice - RSS bandit