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:
- Use tests inside the project and enclose them inside conditional compilation arguments
- Use a separate test project and “link“ to the actual source files you want to use
- Right click on project
- Add Existing item
- in the browse dialog, highlight the file in the tested project
- open the small menu on the 'Open“ button
- select “Link file“
- 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.