Testing an inheriting C # class
I have the following code in c♯ but cannot figure out how to test it; I need to test aMethodUnderTest. I cannot change ABaseClass like in the library. But if I have to test AClass, I need to be able to establish what TheThing returns. Anyone have any ideas or experience with testing this type of code?
public ABaseClass
{
protected ThingBaseClass theThing {get;}
public virtual ....
...
}
public AClassUnderTest : ABaseClass
{
public MyThing Thing
{
get
{
return (MyThing)base.theThing;
}
}
public void aMethedUnderTest()
{
Thing.doSomething();
}
}
Note. The initial value for the Thing parameter is null. TheThing doesn't have a public setter.
+3
source to share
3 answers
You can use mocking libraries like Moles. This way you can set the value to "thing" from your test code. http://research.microsoft.com/en-us/projects/moles/
0
source to share