chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
1. How to mock a method inside constructor of the class?
2. How can I access private/protected - variables/properties in my testing class for testing purpose.

Kindly let me know. Thanks
asked by sony (7.2k points)

2 Answers

0 votes
Hi Sony,

1. Faking static methods called in a constructor is possible like any other call.
if your constructor is calling a method of its own class, you can fake the call using this API:
// Create a mock for class MyClass (Foo is the method called in the constructor)
Mock mock = MockManager.Mock<MyClass>(Constructor.NotMocked);
// Faking the call to Foo
// The actual call to the constructor - Foo will not be called
MyClass t = new MyClass();

You can check our online help for all of the above API...

2. See the link in your previous question on the forum...
Is the ObjectState API not enough? What are you trying to accomplish?


TypeMock Support
answered by yonatan (1.6k points)
0 votes
Thanks very much. Its working.
answered by sony (7.2k points)