---
title: "A simple way to unit-test internal classes"
url: "https://osherove.com/blog/2004/7/10/a-simple-way-to-unit-test-internal-classes.md"
canonical: "https://osherove.com/blog/2004/7/10/a-simple-way-to-unit-test-internal-classes.html"
published: "2004-07-10T14:34:00"
updated: "2004-07-10T14:34:00"
tags: ["Agile Related"]
author: "Roy Osherove"
description: "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.…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# A simple way to unit-test internal classes

By Roy Osherove July 10, 2004 In [Agile Related](https://osherove.com/blog/category/agile-related)

**Historical article** · Originally published July 10, 2004; technical details may be outdated.

[Jamie Cansdale](http://weblogs.asp.net/nunitaddin) (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.

[Download the file here](http://dev.magen.com/Agile/Code/NUnitFramework.cs.zip).

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.

## More in Agile Related

[All posts in Agile Related](https://osherove.com/blog/category/agile-related)

- Jul 19, 2004

    ### [Database Unit Testing issues and solutions: Rollback And RestoreDatabase abilities](https://osherove.com/blog/2004/7/19/database-unit-testing-issues-and-solutions-rollback-and-rest.html)

- Jul 11, 2004

    ### [Introducing: NUnitX and the Rollback attribute - Seamless database rollback with Nunit](https://osherove.com/blog/2004/7/11/introducing-nunitx-and-the-rollback-attribute-seamless-datab.html)

- Jul 2, 2004

    ### [2nd Test Driven Development Workshop](https://osherove.com/blog/2004/7/2/2nd-test-driven-development-workshop.html)

- Jun 22, 2004

    ### [Community reminders: TDD workshop & Blogger Dinner](https://osherove.com/blog/2004/6/22/community-reminders-tdd-workshop-amp-blogger-dinner.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
