I am currently developing a course scheduler for universites in Java. My team and me chose test driven development, espcially for the scheduler itself. I am using JUnit. For nearly every class there has to be JUnit test class. The database schema has become quiet big. Not everything is needed for the OR-mapped classes in the scheduler. In the end there are still 14 classes.
As the scheduler has to be highly configurable, we need classes like: courses, lecturers, students, features, rooms, roomRequiredFeatures, timeSlot, lecturerPrefferredTimeSlots, and so on. I wanted to use the @Before annotations to create fixtures (instantiated test objects to test). These test objects reflect one example of a data set from the database.
As a matter of fact, the 14 classess are not very detailed: maybe 3-4 fields. The problem arises as they are bound really tight to each other. THis results in 220 lines code of instanation in the @Before method which is way to much. A common way to deal with this is to write mockups, which simulate the test objects behaviour. But as the classes are very simple there is no way to simulate them.
I am a little bit desperate because I have the feeling our design is flawed. Are there any suggesstions or course of actions for this case?
It was interesting though I am not sure it is the right approach. Before I go into detail with a post of my classes, a question that might resolve this problem:
The data classes I want to test in JUnit have all along the same structure:
They provide class member fields and the whole class can be instantiated using one constructor. As I see yet no sense in using mock up objects, but calling the constructor like this:
This means, I am leaving those values away which I will not test. This seem slike the spirit of mock up objects, yet I do not know if this is the right approach. Furthermore I got the tip tto write factory methods to produce the objects.