I have a class that extends the JUnit TestCase class. The test has a number of ‘setup’ routines that need to be executed. One of these routines is to insert some data into a database for example, another is to send JMS messages onto EMS queues.
Currently, all of this functionality is inside the overridden setUp method in the test class. However, there must be a better way of doing this. I’d possibly want to use dependency injection also to make the test class more generic.
Thanks.
I don’t think dependency injection is (necessarily) the answer unless you plan on writing tests for your test cases. If I were you I’d do the simplest thing possible and that is to extract this setup code into classes. For example, a
JmsSetupclass and aDatabaseSetupclass. Have your setup method create and use these classes.Take it from there, if that starts to get messy you can do more but don’t cross that bridge until you get to it.