You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/build/maven-test-reuse.asciidoc
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,8 +59,10 @@ You can have your test-infrastructure depend on code from `src/main/java` in the
59
59
Cons:
60
60
61
61
* **Broken Design**: +
62
-
The test jar contains all your test-code (compiled from `src/test/java` including `src/test/resources`) and never are a well defined module API (in the example also `SomeClassTest` sneaks in).
62
+
The test jar contains all your test-code (compiled from `src/test/java` including `src/test/resources`) and never has a well defined module API (in the example also `SomeClassTest` sneaks in).
63
63
Therefore you mess your design of test-infrastructure since also JUnit tests from other modles sneak onto the classpath of other modules and get visible in code-completion, etc.
64
+
However, your tests of a module should be considered as an "implementation secret".
65
+
The idea of modules is encapsulation (SoC) and if you make all your test-code visible to all other modules you easily violate this principle.
64
66
* **Flawed Dependencies**: +
65
67
The dependency type `test-jar` has been added to maven but due to its complexity it is not consistent.
66
68
You might expect that the test-depdendencies of your `test-jar` dependency are transitive but this is not the case (maven never treats `test` scoped dependencies transitive).
@@ -133,7 +135,7 @@ For each set of reusable test-infrastructure you need to create an additional ma
133
135
Sometimes you end up with a problem since obviously maven does not support cyclic dependencies and has to be able to build each module independently.
134
136
In the example above you might have the problem that `CoolTestExtension` requires `SomeClass`.
135
137
Now if `SomeClassTest` dependends both on `SomeClass` and on `CoolTestExtension`, you end up in a problem that can easily be solved with `test-jars` approach.
136
-
To solve it, you could move `SomeClassTest` to `my-module-test/src/test/java`.
138
+
To solve it without `test-jars`, you could move `SomeClassTest` to `my-module-test/src/test/java`.
137
139
In general it is better to design test-infrastructure to avoid such problems.
0 commit comments