简体   繁体   中英

How to move Unit Test classes automatically in Intellij Idea?

Is there any way, how to make Intellij Idea to move my Unit Test classes automatically to a coresponding package when I move tested class?

For example I have these two classes:

src/main/java/com/MyClass.java
src/test/java/com/MyClassTest.java

When I move

src/main/java/com/MyClass.java

to

src/main/java/com/subpackage/MyClass.java

I need the test class to be moved automatically like this:

src/test/java/com/subpackage/MyClassTest.java

It is the same functionality, that does MoreUnit Eclipse plugin.

Intellij Idea does not support this so far.

You can vote here for a new idea to make this feature happen. https://youtrack.jetbrains.com/issue/IDEA-20779#tab=Comments&u=1481384491786

Edit 2018: Intellij Idea now contains this functionality.

Edit 2018-08: It seems that it does not work anymore or it never worked and I just thought it worked.

I use Intellij 14.0.2 (what version do you use ?), and its not part of the refactor functionality. Im afraid you will also have to go to your Test class and refactor a move on it also.

If this is a feature yo would like to see you can riase a request. In doing so you might actually find the functionality is actually in it , just hard to find.

https://intellij-support.jetbrains.com/hc/en-us/requests/new

On IntelliJ 2021.1 automatic Test Unit Class package move as the Source Class move to another package does not work.

The only way that I've found for this to work was to install the plug-in UnitVisualizer . After installing the plug-in as the Source Class moves from one package to another also the respective Test Unit Class moves to the same package on the test directory. Also bulk classes package moves also work with the plug-in.

The link to the plug-in : https://plugins.jetbrains.com/plugin/10493-unitvisualizer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM