Class definition in test directory

Hi,

I have a project which contains 2 modules (module1 and module2), each having one test directory (test1, and respectively test2). A class in test1 extends a class defined in test2.
Although module1 has module2 in its dependencies list, it seems that IDEA cannot handle this situation correctly and cannot compile class1.

Any hints?

10 comments

Hi Andrei,

That is a very basic setup and everything should work fine.

Please provide a sample project which illustrates the problem

Denis

0

Hi Denis,

The project I'm working on is huge. It's strange because I tried to duplicate it and include only the culprit classes, but in this small version of the project I don't have any problems. I'll try to debug more and let you know if I can come up with something.

0

I found another problem, probably related to the original one (I think the dependency graph is similar, though more complex in the first case).
So I have one project with src and test. A class in src (BaseRegressionTst) uses a class in test (MockGateway). Compilation fails when importing.
Please see attached project.



Attachment(s):
test.zip
0

The ide functions as designed here - test classes can use either test or production classes but production classes are unaware of test classes.

Denis

0

Strange, I want to switch from Eclipse (where this was possible), but cannot run some tests because of this missing feature in Intellij IDEA. Any plans to add it in the future? Thanks.

0

It would be strange if production code depends on test code.

Denis

0

I agree with you, but it's not my code. All I want is to use your product in this case and I can't. I think an IDE shouldn't enforce code design rules. Switching back to Eclipse.

0

So to make it clear I think IDEA is an awesome IDE, I'm now in the evaluation period and think seriously to buy it at the end. But in my opinion cases like this should be left to the programmer's decision (e.g. choosing whatever he wants in the classpath). Eclipse is more flexible in this regard. For instance, using test clases in production should be configurable (e.g. a settings option), or if not, an warning can be issued. But, not even allowing the comilation is too restrictive. Again, Denis thanks for the help and I hope my feedback was useful.

0

There is no point in using test classes in production because they become production classes.

You can always adjust your ide module settings accordingly, i.e. change source root type from 'test' to 'production'.

Denis

0

Can't do that because when I mark the test dir in Module2 as src and then run all tests from test in Module1, Intellij also runs the tests in Module2 (??). Furthermore, because the tests from Module2 open some files using relative paths to Module2 and because the JUnit run configuration working directory is set to $MODULE_DIR$, these tests will fail (obviously, because I want to run the tests in Module1, hence $MODULE_DIR$ = Module1 dir).

0

Please sign in to leave a comment.