When testing, sometimes a helper method can be useful for repeated task e.g. in test setup.
Concrete example:
We have certain tests against our rest interface using Spring's RestTemplate
. To make it easier, the requests are sent with the help of a helper method (let's call it method A()
for now), which returns the objects from the response.
This helper method A()
seems to pollute the test class, as it is a method which is actually not a test itself. Having multiple helper methods in a test class has a negative effect regarding the overview.
Is it acceptable to create a second class next to the test class, which is containing all helper method? What would be the difficulties if doing so? Or are there any other ways to keep a good overview of the test class?
MyTestClass
-> containing only methods which are a actuall testMyTestClassUtil
-> containing all helper methods that are used byMyTestClass
RestTemplate
is simulating a client. Although I think this shouldn't really matter. The main issue is, that there is a helper method which is used by multiple tests.MyTestClassUtil
doesn't really tell me what that class is for.MyTestClassCommonSetup
or some such would seem a better name.