views:

19

answers:

1

Hi,

I am coding some unit tests and wondered, is it in the duty of Typemock to replace paremeters?

For example, I have a method which relies on an object and in this object's constructor are some assemblies to analyze (a string array).

Would I be on the right track to mock the class containing the method and then pass in my own parameters? But this in itself has its own overhead. Would it not be better to swap the the parameters of the actual class being tested? Is this possible?

Finally, I seem to have realised that if I want easily tested code then rather having method-level variables which I want to mock, they should be fields and thus accessible from outside. Constructor set variables should assign to references which are fields. Would you agree with this?

I know this may be a noobish question but I haven't use mocking much.

Thanks

A: 

Hi,

If you'll post a code sample of you are trying to do I can give a better answer.
Basically a you want to mock classes that you want to ignore so most of the times you can pass null or any default value to faked methods since you really don't care about the implementation of the faked types.
In rear cases where you want to call constructors and pass arguments you can an overload of
Isolate.Fake.Instance<>() that accepts as parameters the default constructor behavior and a list of arguments to pass

var fake = Isolate.Fake.Instance<Foo>(Members.ReturnRecursiveFakes, ConstructorWillBe.Called, BaseConstructorWillBe.Ignored, "First Argument", "Second argument");

About the second question:
First Fields shouldn't be accessed from outside, in fact it's harder to fake fields. use properties instead.
Second, use fields/properties when you need to keep state of the class other than that use local variables.

Ohad Horesh