---
title: "Partial Classes - Add to your Unit Testing Bag of Tricks"
url: "https://osherove.com/blog/2006/4/14/partial-classes-add-to-your-unit-testing-bag-of-tricks.md"
canonical: "https://osherove.com/blog/2006/4/14/partial-classes-add-to-your-unit-testing-bag-of-tricks.html"
published: "2006-04-14T22:07:00"
updated: "2006-04-14T22:07:00"
tags: [".NET"]
author: "Roy Osherove"
description: "Ralf has a nice tidbit about how .NET 2.0 Partial Classes can help you with writing unit tests for methods on classes that are otherwise harder to get to. It's a nice trick to add to the trick bag, though I'd argue that…"
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/"
---

# Partial Classes - Add to your Unit Testing Bag of Tricks

By Roy Osherove April 14, 2006 In [.NET](https://osherove.com/blog/category/net)

**Historical article** · Originally published April 14, 2006; technical details may be outdated.

[Ralf has a nice tidbit](http://weblogs.asp.net/ralfw/archive/2006/04/14/442836.aspx) about how .NET 2.0 [Partial Classes](http://www.devx.com/dotnet/Article/22603) can help you with writing unit tests for methods on classes that are otherwise harder to get to.

It's a nice trick to add to the trick bag, though I'd argue that if you were doing Test-Driven-Development in the first place, you'd have [a testable design out-of-the-box](http://weblogs.asp.net/rosherove/articles/Design4Tesatbility1.aspx), and you wouldn't need to come up with clever hacks such as these.

Having said that, sometimes you just don't have a choice and you need to write tests for legacy code (a.k.a "code that works"), and in that case, this just might be a lifesaver.

Another lifesaving tool to use with your legacy code would be [TypeMock](http://www.typemock.com/). I recommend you take a long hard look at that little miracle of a tool (which was recently transferred into Israeli ownership, BTW) that can help you overcome lots of legacy code coupling issues in your tests. I should do a whole article on that when I get the time..

Cross Posted from Blogs.Microsoft.Co.Il/Blogs/Royo

## More in .NET

[All posts in .NET](https://osherove.com/blog/category/net)

- May 14, 2006

    ### [Small Tip: Getting the name of the current or calling method at runtime for debugging](https://osherove.com/blog/2006/5/14/small-tip-getting-the-name-of-the-current-or-calling-method.html)

- Apr 27, 2006

    ### [Persistore - Interesting attempt at a .NET Persistence Engine? You decide.](https://osherove.com/blog/2006/4/27/persistore-interesting-attempt-at-a-net-persistence-engine-y.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/
