I have a multimodule project in Intellij and I have a bunch of cucumber fixtures in the test sources of one submodule that I'd like to reuse in another submodule. If I add the other module, as a dependency then its normal ouptut directory gets added to the junit classpath but not its tests output.
Is it possible to have intellij also export a modules test directories and allow other modules to use them?
Yes you can but it's not simple.
So you have Module-A and Module-B.
Module-B has a TestClass
that perhaps extends an AbstractClass or uses some static helpers from Module-A
Note: This will only work in intellij, if you are using maven or gradle you will need to check this will still build ok.
Here is what you need to do.
(Ctrl+Alt+Shift+S - win/linux)
C:\dev\projects\myProject\moduleA\build\testclasses
or similar.(Alt+Insert)
and add a new Library (No 2 on the options)C:\dev\projects\myProject\moduleA\build\testclasses
and click OK. You will now have the classes for your Module-A in here. Name it something suitable Module-A Tests
and change the Level option to Module Library.(Alt+Insert)
to add the source in as well. Navigate to the test src files. E.G.: C:\dev\projects\myProject\moduleA\src\test
and add this and you will now have a Sources added as well.
And now you have test depencies linked between modules.
If you can think of a better solution please let me know but this is the simplest way I have found to do it.
maybe, but you should be doing this through your automated build, i.e. in maven, not your IDE. if you publish the tests of a maven module as a separate dependency (something that I do), you can add the tests jar as a dep of the other module. IDEA of course will handle this automatically.
http://maven.apache.org/guides/mini/guide-attached-tests.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With