Java 如何在 Eclipse 中默认新 JUnit 测试的源文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/69063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 07:54:46  来源:igfitidea点击:

How to default the source folder for new JUnit tests in Eclipse?

javaeclipsejunitusability

提问by Andrew Swan

Most of our Eclipse projects have multiple source folders, for example:

我们的大部分 Eclipse 项目都有多个源文件夹,例如:

  • src/main/java
  • src/test/java
  • 源代码/主/Java
  • 源代码/测试/Java

When you right-click on a class and choose New JUnit Test, the default source folder for the new test is "src/main/java" (presumably the first source folder listed in the project properties).

当您右键单击一个类并选择 New JUnit Test 时,新测试的默认源文件夹是“src/main/java”(大概是项目属性中列出的第一个源文件夹)。

Is there any way to change the default source folder for new JUnit tests, so that when I do the above action, the new test will be created in say the "src/test/java" folder by default?

有什么方法可以更改新 JUnit 测试的默认源文件夹,以便当我执行上述操作时,默认情况下将在“src/test/java”文件夹中创建新测试?

采纳答案by pauxu

I use moreUnit, an Eclipse plugin to assist writing unit tests. Among other features, it lets you configure the default source folder of tests.

我使用moreUnit,一个 Eclipse 插件来帮助编写单元测试。除其他功能外,它还允许您配置测试的默认源文件夹。

回答by Dave L.

No.

不。

Unless you change the plugin code, the default source folder is always the same as that containing the class you right clicked on (not necessarily the first source folder listed). I agree, it would be nice to be able to change it!

除非您更改插件代码,否则默认源文件夹始终与包含您右键单击的类的文件夹相同(不一定是列出的第一个源文件夹)。我同意,能够改变它会很好!

回答by fastcodejava

Now you can use my fast code eclipse plug-in. With this plug-in you can configure the test path to be src/test/javaonly once. It also has a jump to the unit test feature. It is available at : http://fast-code.sourceforge.net/.

现在你可以使用我的快速代码eclipse插件了。使用此插件,您可以将测试路径配置为src/test/java仅一次。它还可以跳转到单元测试功能。可从以下网址获得:http: //fast-code.sourceforge.net/