Java 如何在 Intellij 13 中创建测试目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28160379/
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
How to create a test directory in Intellij 13?
提问by eze
I'm an Intellij noob using v13.
我是一个使用 v13 的 Intellij 菜鸟。
I have a simple java project (default) structure that looks like:
我有一个简单的 java 项目(默认)结构,如下所示:
[] .idea
[] src
[] com.test
mytestClass1
mytestClass2
Now, I want to write a simple test and I'd like to put that code in /src/test/java directory. So I decided to change my project format so that it looks like:
现在,我想编写一个简单的测试,并将该代码放在 /src/test/java 目录中。所以我决定改变我的项目格式,使它看起来像:
[] .idea
[] src
[] main
[] java
[] resources
[] test
[] java
[] resources
After I create that structure, I'd obviously like to move my current classes in src to the main/java/com... structure.
创建该结构后,我显然希望将 src 中的当前类移动到 main/java/com... 结构。
I've read all about content roots and project structure. The info even states, "Folders within content roots can be assigned to the following categories: sources, test sources, generated sources, generated test sources and excluded folders (in Java modules - also resources and test resources)"
我已经阅读了所有关于内容根和项目结构的内容。该信息甚至指出,“内容根目录中的文件夹可以分配到以下类别:源、测试源、生成的源、生成的测试源和排除的文件夹(在 Java 模块中 - 还有资源和测试资源)”
I've tried right-clicking on the project name then New -> Directory then entering "src/main/java" (also tried it with a leading slash) but when I right-click my new directory and select "Mark Directory As" the only option is Excluded.
我尝试右键单击项目名称,然后新建 -> 目录,然后输入“src/main/java”(也尝试使用前导斜杠)但是当我右键单击我的新目录并选择“将目录标记为”唯一的选择是Excluded。
If I create a new directory in the root, I can select Mark Directory As Test Sources Rootbut it still hangs off the root like:
如果我在根目录中创建一个新目录,我可以选择将目录标记为测试源根目录,但它仍然挂在根目录下,例如:
[] .idea
[] java
[] src
[] com.test
Can someone please tell me how to migrate to my desired structure?
有人可以告诉我如何迁移到我想要的结构吗?
采纳答案by mariusz-s
You should have structure like this one:
你应该有这样的结构:
[] .idea
[] src
[] main
[] java
com.simpleproject
SimpleClass.java
[] resources
[] test
[] java
com.simpleproject
SimpleClassTest.java
[] resources
After that go to: File->Project Structure->Modules and in "Sources" tab you can choose which folder is "test folder" (usually java in test), which "sources" (usually java in main) etc by clicking "Mark as" options.
之后转到:文件->项目结构->模块,在“源”选项卡中,您可以通过单击“选择哪个文件夹是“测试文件夹”(通常在测试中为java),哪个“源”(通常在主中为java)等标记为”选项。