如何在 Intellij 13 中创建测试目录? [英] How to create a test directory in Intellij 13?

查看:24
本文介绍了如何在 Intellij 13 中创建测试目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个使用 v13 的 Intellij 菜鸟.

I'm an Intellij noob using v13.

我有一个简单的 Java 项目(默认)结构,如下所示:

I have a simple java project (default) structure that looks like:

  [] .idea
  [] src
     [] com.test
          mytestClass1
          mytestClass2

现在,我想编写一个简单的测试,并将该代码放在/src/test/java 目录中.所以我决定改变我的项目格式,使它看起来像:

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:

 [] .idea
   [] src
     [] main
        [] java    
        [] resources
     [] test
        [] java    
        [] resources

创建该结构后,我显然希望将 src 中的当前类移动到 main/java/com... 结构.

After I create that structure, I'd obviously like to move my current classes in src to the main/java/com... structure.

我已经阅读了关于内容根和项目结构的所有内容.该信息甚至指出,内容根目录中的文件夹可以分配到以下类别:源、测试源、生成的源、生成的测试源和排除的文件夹(在 Java 模块中 - 还有资源和测试资源)"

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)"

我尝试右键单击项目名称然后新建 -> 目录然后输入src/main/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.

如果我在根目录中创建一个新目录,我可以选择将目录标记为测试源根目录,但它仍然挂在根目录下,例如:

If I create a new directory in the root, I can select Mark Directory As Test Sources Root but it still hangs off the root like:

  [] .idea
  [] java
  [] src
     [] com.test

有人可以告诉我如何迁移到我想要的结构吗?

Can someone please tell me how to migrate to my desired structure?

推荐答案

你应该有这样的结构:

 [] .idea    
 [] src
    [] main
      [] java   
           com.simpleproject
             SimpleClass.java
      [] resources
    [] test
      [] java
           com.simpleproject
             SimpleClassTest.java
      [] resources

之后转到:文件->项目结构->模块,在源"选项卡中,您可以选择哪个文件夹是测试文件夹"(通常是测试中的java),哪个源"(通常是main中的java)等单击标记为"选项.

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.

这篇关于如何在 Intellij 13 中创建测试目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆