A sample example to set private variable to true from unit test class in C#.Net
//TestService.cs
public class TestService
{
private bool _isInitialized = false;
}
//TestServiceUnitTest.cs
using System.Reflection;
public class TestServiceUnitTest
{
private TestService _testService;
[TestInitalize]
private void testInitalize()
{
_testService = new TestService();
}
[TestMethod]
Private void SetInitializeToTrue()
{
FieldInfo field = typeof(TestService).GetField("_isInitialized", BindingFlags.NonPublic | BindingFlags.Instance);
}
//TestService.cs
public class TestService
{
private bool _isInitialized = false;
}
//TestServiceUnitTest.cs
using System.Reflection;
public class TestServiceUnitTest
{
private TestService _testService;
[TestInitalize]
private void testInitalize()
{
_testService = new TestService();
}
[TestMethod]
Private void SetInitializeToTrue()
{
FieldInfo field = typeof(TestService).GetField("_isInitialized", BindingFlags.NonPublic | BindingFlags.Instance);
field.SetValue(_testService , true);
}
0 comments :
Post a Comment