I have simple Java library (with Gradle) that is stored as an artifact on my private Nexus instance. The library provides custom serializer
/deserializer
used in the technology I'm using (details are not really important) - I'm using this library in many projects
Now the problem is that to write integration tests for classes using the library I need to provide some additional configuration for this wrapped serializer
/deserializer
to mock some additional mechanism provided by the technology in production environment (making long story short - there is additional 3rd party service and running this during integration tests would be completely inefficient thus it's better to mock this)
What I've done in this situation - I created some TestUtils
class providing serializer
/deserializer
that is extending library's implementations with proper configuration. The problem is that I need to have a copy of this TestUtils
in every project using the library which obviously is not the best idea because in case of any future changes in the library I will need to manually update TestUtils
in every project that will use newer version of the library
I decided to somehow include TestUtils
class into my library but now I have a problem how to do this in best way, maybe using some Gradle specific way of work that I'm not aware of
What I figure out is to either:
- put the
TestUtils
class to the library'stest
package and put it to the result artifact - seems to be bad idea as described e.g. here: Configure Gradle to include main classes as well as test classes into my .jar archive - put the
TestUtils
class to the library'smain
package (create specific subpackage for this) - which seems for me to be awful idea at least because the developer could use this class accidentally in a production code - create new library named e.g.
my-library-test-utils
- seems to be the most clear way of doing this but will enfore me to handle two artifacts independently and remember to bump uptest-utils
every time the library will be updated - just leave
TestUtils
as it is - use some Gradle's magic to keep library's sources and
TestUtils
together then export it to two artifacts or make something else like exporting fatJar with test-utils inside accesssible from outside, or makeTestUtils
class available only during tests (is this even possible?)
Aucun commentaire:
Enregistrer un commentaire