Mocking in Unit Tests
page 2 of 8
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 35502/ 72

Reflection

The .NET Framework has the ability to reflect and gather metadata about types in an assembly.  The Type class has several methods define that return objects representing a property, method, etc.  These objects are suffixed with -Info and are defined in the System.Reflection namespace.  For instance, if you wanted to get properties of a class, you use GetProperties() to get a list of properties or GetProperty() to get a specific named property.  For each object the type class has these methods defined or you can use GetMember()/GetMembers() to get the MemberInfo objects you may be looking for.

Reflection has some capabilities to get/set values, which help in getting/setting values for an object.  You can somewhat mock a property value because you can change it to be whatever you want to test it as.  This is the capability I build into a Reflection Mock class that made it easier to perform logic mocking in unit tests, but is far short of an actual mock class.

See the Reflection overview for more information.


View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 4:57:24 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search