Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Intellij is it possible for one module to depend on the tests of another module

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?

like image 932
sgargan Avatar asked Jun 08 '12 18:06

sgargan


2 Answers

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.

  1. Goto Project Structure... (Ctrl+Alt+Shift+S - win/linux)
  2. Goto Modules and Look at Module-A's Path Tab
  3. Take a note of the Test output path or copy this. It could be something like this: C:\dev\projects\myProject\moduleA\build\testclasses or similar.
  4. Goto Modules and select Module-B and look at its Dependencies Tab.
  5. You may already have a dependency on Module-A in here for compile time and thats ok.Click on the + or type (Alt+Insert) and add a new Library (No 2 on the options)
  6. On the choose libraries screen select the New Library... button. Select the Java option.
  7. In the dialog that pops up goto the build folder you had above 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.
  8. Click the + button (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.
    1. Click OK and you will come back to the Project Structure dialog.
    2. Now you will have a new Library added to your dependencies. Change the Scope to Test
    3. Press OK at the bottom and your done. You might need to make/clean the project.

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.

like image 118
MJB Avatar answered Oct 05 '22 04:10

MJB


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

like image 25
ianpojman Avatar answered Oct 05 '22 04:10

ianpojman