OT: White Box testing service and command classes

OT: White Box testing service and command classes

Old forum URL: forums.lhotka.net/forums/t/7637.aspx


SonOfPirate posted on Wednesday, September 16, 2009

I've tried posting this question/issue elsewhere but, as usual, I fall back to this community for real answers...

I have an application that I need to develop code-based "unit" tests for and could use some guidance on techniques, tools and best practices.  Here's my situation:

The application has a "service" class which constitutes the public API or main entry point for the application's purpose.  The service class delegates each method call to a command object that carries out that specific function, typically using other commands, business objects, etc.  This is somewhat analogous to the service starting a workflow with various activities executing the individual steps. (In fact, our next iteration may actually do just that.)

At its most basic, we map the service method parameters to properties on the command object and call Execute to carry out the operation which returns a boolean pass/fail indicator.  When applicable, we can then inspect the command's Results property for data to return to the caller.  I want to unit test each piece but am having trouble determining the best approach.

We use Spring.NET factories to instantiate our objects, so when the service class needs a command, it goes to Spring for the instance.  This allows me to create a mock command object for testing purposes.  However, at this point, my test simply consists of the method call into the service with known parameters and a test that the return value is true, indicating that the method was successful.  It certainly doesn't give me any glimpse into what's going on inside the service method and whether it is actually executing correctly.  In fact, right now, my mock command object simply returns true from the Execute method.

What can I do to improve my test(s)?  I'd like to know that the service method is passing the parameters properly to the command and that the service method handles various situations, such as command failure, an excepton occurring during execution, etc.

Thanks in advance!

Copyright (c) Marimer LLC