Can we assign value to private variable using JustMost full version

2 posts, 0 answers
  1. Rajendar
    Rajendar avatar
    69 posts
    Member since:
    Jun 2013

    Posted 24 Jun 2014 Link to this post

    Hi Everyone,

    From this link I understood that we can call private methods and properties but by using JustMock. Can I give some value to private variable in class
    Class JustMock
           private string name="Testing"
           Private string ReturnSomeValue()
                return name;


    Here my question is can I assign my own value to name variable with JustMock


  2. Kaloyan
    Kaloyan avatar
    871 posts

    Posted 26 Jun 2014 Link to this post

    Hi Rajendar,

    The answer is, yes you can. You can achieve this with the JustMock PrivateAccessor , like so:
    public void TestMethod()
        // Arrange
        var test = new Foo();
        var privateAcc = new PrivateAccessor(test);
        privateAcc.SetField("name", "test");
        // Act
        var actual = privateAcc.CallMethod("ReturnSomeValue");
        // Assert
        Assert.AreEqual("test", actual);

    I hope this helps.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. DevCraft R3 2016 release webinar banner
Back to Top