Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Unit Testing in Java How to Test Setting Up a Project for Tests

Ali Baig
PLUS
Ali Baig
Courses Plus Student 120 Points

When I create directory tests and right click > select "Mark Directory as" I see only 1 option Excluded. Using latest IJ

I am unable to create centralize test directory. Right click is not showing me any other option other then Excluded. I am creating directory at top project level by right clicking and selection New > Directory. I am using Windows 10 and latest IJ.

Ido Shenhav
Ido Shenhav
4,577 Points

I'm having the same problem... It's not inside the src or resource directory... Using windows 10 and latest intelliJ

3 Answers

Ido Shenhav
Ido Shenhav
4,577 Points

Okay for those who have the same problem, I've figured it out in my case (partly due to the answer Fahad gave, so thank you Fahad!). So it turned out the 'java-unittesting-vendingmachine' folder was marked as Source Root.

All you have to do is unmark it and you can then mark 'src' as Sources Root and 'tests' as Test Sources Root

Fahad Mutair
Fahad Mutair
10,359 Points

hi Ali Baig , if try to Mark Directory any folder inside resources folder or source folder like (src/main/java/any folder) it will show only Excluded.

Here's my directory structure (using the Maven style):

vending-machine <-- module (content root)
├── src
   ├── main
      └── java <-- sources root
          └── io
              └── github
                  └── adamelliotfields
                      └── Main.java
   └── test
       └── java <-- test sources root
           └── io
               └── github
                   └── adamelliotfields
                       └── MainTest.java
└── vending-machine.iml

When starting a project in IntelliJ, it creates the src folder for you.

Go into terminal and generate the rest (assuming you are in the project root folder):

mkdir -p ./src/main/java/io/github/adamelliotfields
mkdir -p ./src/test/java/io/github/adamelliotfields

Then you can go into Project Structure and label your folders as you wish.

Finally, if you're using Maven or Gradle, it will generate all this automatically for you.