I have to write some integration test classes in the Hybris Commerce Suite and most of them share a common behavior to set up the system (Site, Store, Catalog, Country, ...) or to perform some common action like create a customer.
I created an abstract class that perform all the initialization with constant values in the @Before method and with some common methods like createDefaultCustomer().
All my test classes inherit from this class.
The constant values are separated in different constant classes like
abstract class AbstractTest {
protected static final class USER_CONSTANTS {
};
protected static final class CATALOG_CONSTANTS {
};
protected UserModel createDefaultUser() {
}
}
Now, in order to test, in my subclasses i can do
createDefaultUser();
UserData userData = userFacade.getUserById(USER_CONSTANTS.ID);
assertEquals(USER_CONSTANTS.ID, userData.getId());
If I don't do this there is a lot of duplication in test classes.
My doubt is whether this is acceptable because the abstract class tends to be long and rich of methods or I need to change the design. I would to avoid the creation of separate classes for each group of constants.