Extending Our Mansion

Was this worth all the effort? Let's look at a few extensions of our small framework and think about the impact they may have on our tests. Extension 1: We extend our Logging interface by a log method with an additional module parameter. This parameter specifies which module of the app is currently logging. Impact: One additional test method and some minor refactoring in the LogServerTest, along the following lines:

public class LogServerTest extends TestCase {
 private LogServer logServer;
 private DummyLogger logger;
 protected void setUp() {
 logger = new DummyLogger();
 logServer = new LogServer(logger);
 public void testLoggingWithModule() {
 logServer.log(0, "first line", "test");
 assertEquals("test(0): first line",
 public void testSimpleLogging() {
 logServer.log(0, "first line");
 logServer.log(1, "second line");
 logServer.log("third line");
 assertEquals("(0): first line", logger.getLogString(0));
 assertEquals("(1): second line", logger.getLogString(1));
 assertEquals("(2): third line", logger.getLogString(2));

The tests for the actual loggers remain untouched. Extension 2: We allow a log server to accommodate several loggers, to which it will distribute all log messages. Impact: A few tests here to check for adding and removing of the loggers, and a few tests there to check whether or not each logger receives all messages. Even this bigger functional extension leaves the tests for the actual loggers untouched.

Separating LogServer from Logger and introducing a dummy implementation brought us the additional advantage that, if a test failure occurs, we will be able to precisely locate the problem in the source code. This is possible because we know for a fact that a test failure would be due solely to our log server and not to an error when accessing the file system.