I'm converting an old legacy program to a new OOP design, and I'd like to include Unit Testing, since I've read that's so wonderful.
I'm realizing my OOP design is a huge tree structure of classes.
At top I have a Machine
class has a Model
class, a View
class, and a Controller
class. Each of those classes contains numerous other classes, and those classes in turn contain other classes, and on and on.
It appears Unit Testing has to be done from the bottom up. I can only easily create a leaf class—a class which has no subclasses.
I can't easily create a Machine
class, for instance, because the entire tree of other classes that are needed haven't been written yet.
Are OOP programs grown from the bottom up? I write the leaf classes first, write Unit Tests for those, then the classes that use those leaf classes, and work my way up?
I'd like to test how the controller writes to the screen, to see if that actually works, but to do that I need to instantiate a Controller
class, and a Screen
class, and the Machine
class is what hooks them together, but I can't create a Machine
class because the entire tree of other classes involved haven't been written yet.
So it's sounding like I can't test the design to see if it's viable until all
the code has been written. How does one get around this?
For example (see attached UML diagram), to test if MainMenuController
can put text on the screen, I have to create classes MainMenuController, MenuController, ScreenController, MachineController, Machine, MachineView, ScreenView, ScreenData.
Plus I have to create dummy classes for MachineModel, BetaController,
and possibly others. This seems like a lot of work for Unit Testing.
I also haven't found a good Unit Testing framework. I have Visual Studio 2010, and there is some Unit Testing capability in it. I've tried xUnit
, but couldn't get it to work.