Separation of Interface From Implementation
Because some classes may have references to other classes, testing a class can frequently spill over into testing another class. A common example of this is classes that depend on a database: in order to test the class, the tester often writes code that interacts with the database. This is a mistake, because a unit test should usually not go outside of its own class boundary, and especially should not cross such process/network boundaries because this can introduce unacceptable performance problems to the unit test-suite. Crossing such unit boundaries turns unit tests into integration tests, and when test cases fail, makes it less clear which component is causing the failure. See also Fakes, mocks and integration tests
Instead, the software developer should create an abstract interface around the database queries, and then implement that interface with their own mock object. By abstracting this necessary attachment from the code (temporarily reducing the net effective coupling), the independent unit can be more thoroughly tested than may have been previously achieved. This results in a higher quality unit that is also more maintainable.
Read more about this topic: Unit Testing
Famous quotes containing the words separation of and/or separation:
“... the separation of church and state means separationabsolute and eternalor it means nothing.”
—Agnes E. Meyer (18871970)
“I was the one who was working to destroy the one thing to which I was committed, that is, my relationship with Gilberte; I was doing so by creating, little by little and through the prolonged separation from my friend, not her indifference, but my own. It was toward a long and cruel suicide of the self within myself which loved Gilberte that I continuously set myself ...”
—Marcel Proust (18711922)