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

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

问题描述

我是使用v13的Intellij noob。

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

我尝试右键单击项目名称,然后单击New - > Directory然后输入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 in测试),通过点击标记为选项来源(通常是主要的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天全站免登陆