Unit testing question

  • Thread starter Thread starter CSharper
  • Start date Start date
C

CSharper

I have a class something like the following

class name
{
public string Method1()
{
}
public bool Method2()
{
...
string x = Method1()
....
}
}


I am writing tests for Method2 and when Method1() is called on my
test, I want to pass some orbitary value to make it run. I don't want
the Method1 to execute. I read about Mock, is it the right way to do
it?

Thanks,
 
Have a read about dependency injection, you would need to call method1 from
method2 via a delegate which you pass in. then in the test you can pass in a
mock method and in real life pass in method1.
You would probably benefit from having an overload to method2 which doesnt
take a delegate and passes a delegate to method1 to the overload which takes
one.
 
Back
Top