JUnit tests are not moved correctly when refactoring

I ran into this problem yesterday and it resulted in me having to spend a few hours to refactor my project (should have only taken a few minutes).

I have a project setup like this:

src/java
--various.packages.here
test/java
--same.package.structure.as.src.java.for.unit.tests

src/java is marked as a source folder, and test/java is marked as test source folder.

I moved a lot of packages around to better organize it due some new developement. When I moved a package (using drag-n-drop) in src/java I got a warning about the move affecting both src/java and test/java (which would be expected). So I press Yes and IntelliJ does the refactor and when I look all the unit tests for that package are now
under src/java. i.e. it combined src/java and test/java instead of recognizing it was a different source path and just duplicating the package move under test/java.

Is this a bug or by design?

As a workaround it finally dawned on me to remove test/java as a test source location under project settings, then do the refactoring to src/java. Then I unselected src/java as a source location and reselected test/java and then duplicated my refactoring for test/java. This was ok, but defintely not pleasurable:-)

(IntelliJ 8.1.4)

8 comments

Hello Michael,

It is not evident but if you uncheck "Move to another source folder" in Move
dialog then IDEA 9 would behave as you want. I mean it would leave package
directories in the same root

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

I ran into this problem yesterday and it resulted in me having to
spend a few hours to refactor my project (should have only taken a few
minutes).

I have a project setup like this:

src/java
--various.pakcages.here
test/java
--same.package.structure.as.src.java.for.unit.tests
src/java is marked as a source folder, and test/java is marked as test
source folder.

I moved a lot of packages around to better organize it due some new
developement. When I moved a package (using drag-n-drop) in src/java I
got a warning about the move affecting both src/java and test/java
(which would be expected). So I press Yes and IntelliJ does the
refactor and when I look all the unit tests for that package are now

under src/java. i.e. it combined src/java and test/java instead of
recognizing it was a different source path and just duplicating the
package move under test/java.

Is this a bug or by design?

As a workaround it finally dawned on me to remove test/java as a test
source location under project settings, then do the refactoring to
src/java. Then I unselected src/java as a source location and
reselected test/java and then duplicated my refactoring for test/java.
This was ok, but defintely not pleasurable:-)

---
Original message URL:
http://www.jetbrains.net/devnet/message/5263535#5263535



0

Is there a equivalent option for 8.x?

0

Hello Michael,

I am afraid that the option doesn't work in IDEA 8 as I fixed it for IDEA 9.x

Sorry for the inconvenience
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Is there a equivalent option for 8.x?

---
Original message URL:
http://www.jetbrains.net/devnet/message/5263537#5263537



0

In case someone hits this thread on a search I just want to point out that in IntelliJ 10 the option is now "Don't move to another source folder" and you should leave it checked if you want your tests to stay under test/java. (it gives you a warning that the package corresponds to two different directories, just answer yes to that dialog, then you will get the dialog that has this option).

Also, this functionality (leaving source under their root and tests under their root during a move) works great! Did a lot of reorganizing of code that had associated unit tests and IntelliJ moved everything without problems including moving the unit tests to the new corresponding packages under test/java.

0

Is it just me, or does this no longer work in Intellij 11? No matter what options I try, it always dumps the unit tests in the production source directory.

0

No, you should choose "Leave in the same source root" option in the destination directory folder. Thanks

0

Hi Anna, I've tried that and it still does not work.

0

James,
it works for me. Could you please describe your case in more details? How do you invoke the refactoring? Do you move into existing directory or to a new one? Thanks

0

Please sign in to leave a comment.