| || |
Problem: An issue with mock objects while nunit testing using c#
I m using mock objects in the Nunit unit tests using
C#. I am facing this problem
suppose I have a object ABC which I want to test. This
object has Another object XYZ as its member variable.
Something like this.
XYX p; (XYZ can be fetched using the get method and
there is no set method)
I am creating mock object of the XYZ class. I can
successfully creat the XYZ mock object. When I create
an instance of ABC class, an instance of XYZ is being
created which I intend to overwrite wid my mock
object. The problem is that the XYZ class in the ABC
class just provides the Get method to the Class ABC,
so I cannot overwrite the instance of XYZ with my mock
object of XYZ. Is ther a hack to overcome this
Thank you in advance.
Re: Problem: An issue with mock objects while nunit testing using c#
There are several things you can do:
1. Decide that you test ABC and XYZ as one unit. This means that you will not create a mock XYZ. There are many considerations for not testing each and every class in isolation. (see: http://www.qualityprogramming.org/Te...operTests.htm)
2. Write a set method within ABC that will be only part of the class in DEBUG mode. This way you will be able to use it in testing.