Testing code that depends on the corporate library, even if it does not provide interfaces?

Maybe I'm showing that I don’t understand dependency injection and testing, but I don’t understand how using dependency injection with classes that don’t implement interfaces helps me when testing?

For example, the Enterprise Library 5.0 documentation talks about using a Unity container to create instances. It says it helps "testability: it is trivial to isolate classes from dependencies using the dependency injection style." MSDN

How can I use this in my unit tests? In their example, there is a constructor with parameters as classes, not interfaces:

public class TaxCalculator 
{
  private ExceptionManager _exceptionManager;
  private LogWriter _logWriter;

  public TaxCalculator(ExceptionManager em, LogWriter lw) 
  {
    this._exceptionManager = em;
    this._logWriter = lw;
  }
}
+5
3

" ", . - . , .

, , ( , , ..), , Enterprise Library ( ). .

, , / Test Doubles , (, IMyOwnLogger). , , . , , , .

: " TDD: .

+9

. - . .

public abstract class LogWriter
{
    public abstract void Write(string message);
}

, :

Mock<LogWriter> logWriter = new Mock<LogWriter>();
TaxCalculator calc = new TaxCalculator(logWriter.Object);

, - YAGNI. ExceptionManager, ? TDD, . /.

.

UPDATE: , Microsoft.Practices.EnterpriseLibrary( ). , Microsoft.Practices. "" ExceptionManager, / , .

+4

sealed, , , . , - sealed .., .

+3

All Articles