Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

java - How to create a test directory in Intellij 13?

I'm an Intellij noob using v13.

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

  [] .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:

 [] .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.

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...