Hi, I am struggling to figure out what the Maven Way is for distributing test utils.
Say I have a project "foo" along with some unit tests for it. Moreover, I have some utilities that help in testing "foo" (e.g., test data builders or test fixtures). These utilities are used by the unit tests for "foo", but may also be useful to projects depending on "foo" (e.g., a FooTestDataBuilder that produces Foo instances could also be used in the tests of a dependent project "bar"). The question is where to place these test utilities and how to depend on them. 1. I could follow the "guide to using attached tests" [1], place the test utilizes in foo/src/test/java, and attach the test-jar to "foo". Then, a dependent project "bar" could depend on the test-jar in its test scope. Alas, as the test scope is not transitive, I would need to declare all test-dependencies of "foo" again in "bar", even though I may not even use them directly (e.g., if the FooTestDataBuilder uses them only internally). 2. I could split "foo" into three projects: "foo", "foo-test-utils", and "foo-tests", with the latter depending on both "foo-test-utils" and "foo-tests". A project "bar" would then simply depend on "foo" in compile scope and "foo-test-utils" in test scope. This would make all dependencies explicit, but would result in some oddities, e.g., foo-tests/src/main/java being empty, as all tests need to be placed in tests/src/test/java to be picked up by Surefire. 3. I could split "foo" into just two projects, "foo" and "foo-testing". foo-testing/src/main/java would the contain the test utilities for "foo", whereas foo-testing/src/test/java would contain the actual tests. This is again somewhat odd, as the tests in foo-testing/src/test/java are not testing "foo-testing" but "foo". 4. Option 4 is the most natural way, but unfortunately it doesn't work, because it introduces a cyclic dependency: Have "foo" and "foo-test-utils" and let the tests of "foo" depend on "foo-test-utils". Am I missing something? In particular, why is [1] apparently the recommended approach, even though it requires you to duplicate dependency information? Any suggestions are greatly appreciated. Best wishes, Andreas [1] <https://maven.apache.org/guides/mini/guide-attached-tests.html>
signature.asc
Description: OpenPGP digital signature