rickgaribay.net

Space shuttles aren't built for rocket scientists, they're built for astronauts. The goal isn't the ship, its the moon.
posts - 303, comments - 180, trackbacks - 35

My Links

News

Where's Rick?


AgileAlliance deliver:Agile 2019- 4/29
Desert Code Camp, PHX - 10/11
VS Live Austin, TX - 6/3
VS Live SF - 6/17


About Me
Hands on leader, developer, architect specializing in the design and delivery of distributed systems in lean, agile environments with an emphasis in continuous improvement across people, process and technology. Speaker and published author with 18 years' experience leading the delivery of large and/or complex, high-impact distributed solutions in Retail, Intelligent Transportation, and Gaming & Hospitality.

I'm currently a Principal Engineer at Amazon, within the North America Consumer organization leading our global listings strategy that enable bulk and non-bulk listing experiences for our WW Selling Partners via apps, devices and APIs.

Full bio

Note: All postings on this site are my own and don’t necessarily represent the views of my employer.



Check out my publications on Amazon Kindle!





Archives

Post Categories

Published Works

Unit Testing Private Methods

We had a discussion today around how to test private methods in unit tests. I could have sworn I blogged about this about a year ago but I guess not.

Anyway, let's say you have Implementation.dll that contains a private method. Within the AssemblyInfo.cs file for that assembly, simply add the InternalsVisibleTo attribute, naming the assembly that will be making the calls into the implementation.

For example, if MyUnitTests.dll will call private methods on a class in Implementation.dll, add the following to the AssemblyInfo.cs file for Implementation.dll:

[assembly: InternalsVisibleTo("MyUnitTestAssembly.dll")]

Scary? Yes, but also very useful if you are truly applying TDD.

More info here: http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx

 

Print | posted on Wednesday, August 01, 2007 2:59 PM | Filed Under [ Processs ]

Feedback

Gravatar

# re: Unit Testing Private Methods

Does this work with private methods? I thought in only worked with internal ones.
9/10/2007 7:46 PM | Greg Arzoomanian
Gravatar

# re: Unit Testing Private Methods

This *really* isn't a good, not to mention, safe, way to design code. Instead, use VS' built-in ability to create reflective interfaces to private methods using the "Create Private Accessor" tool.
9/17/2007 10:55 AM | Nathan Smith
Gravatar

# re: Unit Testing Private Methods

Sorry Nathan but the "private accessor" may seem like a siimple and straightforward way of testing a non-public class/method, but it just creates to much unneccessary code on large systems. I've been in this IT programming/archtecture gig for nearly 30 years (OOD/OOP since 91) and the InternalsVisibleTo directive is a god send for developing and maintaining test harnesses and doing TDD on the MS platform. Regards :)
6/19/2009 2:14 PM | bill in san diego
Comments have been closed on this topic.

Powered by: