Avoid code duplication at test level with Util class

113 Views Asked by At

I've got a Java project in Maven with the following (simplified) structure:

module-alpha
    src
        main
        test
            java
                TestUtils.java <-----------------------
module-beta
    src
        main
        test
            java
                TestUtils.java <-----------------------
...
module-yotta
    src
        main
        test
            java
                TestUtils.java <-----------------------

There is a class TestUtils.java repeating itself along the project. (It's a simple class I wrote as a library for needed stuff in every unit test.)

How can I avoid this code redundancy?

1

There are 1 best solutions below

2
On

You need to create a different maven project that include TestUtils.java and build it as a jar e.g. test.jar.

Then use test.jar as a local dependency of relevant projects.