I saw several answers regarding "how to drown out your classes so you can control what happens in SUT."
They say one thing:
Create an interface and add this interface using dependency injection, and create a stub using the same interface that you then enter into the SUT.
However, what I learned in my previous jobs:
If you are unit test, you check all classes / functionality.
Does this mean that for each class that has a specific function layout, you need to create an interface?
This would mean that the number of classes / files is about twice as large.
As you can see from the example below, is this a βway to goβ or am I missing something during unit testing?
As a note: I am using VS2012 Express. This means the lack of a "Faker" frame. I use the standard unit testing system VS2012.
As a very, very simple example that allows me to drown out every interface passed to the SUT.
IFoo.cs
public interface IFoo { string GetName(); }
Foo.cs
public class Foo : IFoo { public string GetName() { return "logic goes here"; } }
IBar.cs:
public interface IBar : IFoo { IFoo GetFoo(); }
Bar.cs:
public class Bar : IBar { public string GetName() { return "logic goes here"; } public IFoo GetFoo() { return null;
IBaz.cs:
public interface IBaz { IBar GetBar(); }
Baz.cs:
public class Baz { public IBar GetBar() { return null;
source share