One way to do that is using mock objects. They simulate the behavior of real objects and is not needed the entire application for the test.
For example, in a Restaurant, the Waiter's job depends on the Cook's job . So, when you test the Waiter's job, you will test the job of the two employees.

If you want to test only de Waiter's job, you need to create a mock object in order to simulate the other employee's jobs.

NMock2 is one option to create mock objects. It can be downloaded from http://www.nmock.org/. As follows you will find the code to create the mock of the Cook using NMock2:
// Create the order and dishes for the test // Create the mock of the Cook // Asign the mock object as Cook of the restaurant // Send the order to the Waiter |
The previous code builds a mock that expects one execution of the GetDishes method with the order as a parameter, and it must return the list of dishes specified.
So, when this test is executed, the Waiter uses the mock of the Cook, which returns the dishes that we have created.
For more details about creating mocks, you can watch the video (in Spanish language) with the entire explanation and download the presentation and code (in Spanish language).
Thanks to Miguel and Rodolfo for helping me with the video.