Here how it works.
Let assume that we have SampleClass with private field, property and
method:
public class SampleClass
{
private string _privateStringField = "Test";
private string PrivateStringProperty
{
get { return _privateStringField; }
}
private int PrivateMethod(int x, int y)
{
return x + y;
}
}
It looks simple enough. And here how you would test it. You will
need to add reference to MbUnit.Framework.2.0.dll in order to use
Reflector class.
using MbUnit.Framework;
using MbUnit.Framework.Reflection;
namespace MbUnitPrivate
{
[TestFixture]
public class SampleTests
{
Reflector _reflector;
[SetUp]
public void Init()
{
SampleClass sc = new SampleClass();
_reflector = new Reflector(sc);
}
[Test]
public void NonPublicField_Test()
{
object result =
_reflector.GetNonPublicField("_privateStringField");
Assert.AreEqual("Test", result);
}
[Test]
public void NonPublicProperty_Test()
{
object result =
_reflector.GetNonPublicProperty("PrivateStringProperty");
Assert.AreEqual("Test", result);
}
[Test]
public void PrivateMethod_Test()
{
object result =
_reflector.RunPrivateMethod("PrivateMethod", 5, 7);
Assert.AreEqual(12, result);
}
}
}
Hope it helps.
Vadim
On Mar 16, 2:52 pm, "SteveM" <[EMAIL PROTECTED]> wrote:
> I see that the latest download (2.4) has added the capability to test
> private methods. This is exactly what I have been looking for, Are
> there any examples or documentation on this new feature anywhere?
>
> Thanks
> -SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---