Mocks / stubs / fakes / test double / etc. well versed in unit tests and allow testing the tested class / system in isolation. Integration tests may not use any layouts; they actually end up in a database or other external dependency.
You use a layout or blank when you need to. This is usually due to the fact that the class you are trying to test depends on the interface. For TDD, you want to program interfaces, not implementations, and use dependency injection (generally speaking).
A very simple case:
public class ClassToTest { public ClassToTest(IDependency dependency) { _dependency = dependency; } public bool MethodToTest() { return _dependency.DoSomething(); } }
IDependency is an interface, possibly with expensive calls (access to a database, calls to web services, etc.). The test method may contain code similar to:
// Arrange var mock = new Mock<IDependency>(); mock.Setup(x => x.DoSomething()).Returns(true); var systemUnderTest = new ClassToTest(mock.Object); // Act bool result = systemUnderTest.MethodToTest(); // Assert Assert.That(result, Is.True);
Please note that I am doing state testing (as @Finglas suggested), and I am only arguing against the system under test (an instance of the class I'm testing). I can check the property values (state) or the return value of the method, as this case shows.
I recommend reading The Art of Unit Testing , especially if you are using .NET.
Truewill
source share