Imagine that you have an application and you want to do unit tests and functional tests on it (it's not so hard to imagine). You may have an abstract class, let it be called AbstractTestClass, from which all of your unit tests are distributed.
AbstractTestClass will look something like this (using JUnit 4):
class AbstractTestClass { boolean setupDone = false; @Before public void before() { if(!setupDone) {
This is what I'm fighting. I have another abstract class that checks web interfaces:
class AbstractWebTestClass extends WebTestCase { boolean setupDone = false; @Before public void before() { if(!setupDone) {
This is almost the same class, except that it extends WebTestCase . This design can give me the opportunity to have the same data during unit testing than when testing the interface.
Usually, when dealing with such a problem, you should maintain composition over inheritance or use a strategy template.
Unfortunately, I don’t really like the idea of composition over inheritance in this particular scenario, and I don’t see how I can use the strategy template, there is probably a design flaw and I can’t see the solution.
How can I design this architecture to achieve my goal.
source share