IDEA 11.1.2 jUnit test classes (package issue)

Hi all,

having a "src" and a "test" folder for my module, it seems that I cannot reference to my source classes from the test class. This was working in previous versions, which is confusing me right now. Maybe I need to configure something additionally.
Here's my example:

src (folder)

test (folder)

actually with this setup I shouldn't need to import "". But then "HelloWorld" won't be recognized in my test class (Cannot resolve symbol 'HelloWorld').

When importing "" in my test class, which should be already defined through package definition, IDEA marks this particular import as not required (greyed out).

I actually thought when defining a "package", the requirement of importing classes from that particular package should be obsolete. Can anyone help me please?

Comment actions Permalink

I ran into that issue once. It likely means that IDEA's indexes are corrupt. So in once case it (incorrectly) thinks you need to do the import. But in the other, it realizes you do not. Go to File > Invalidate caches. Then restart IDEA and let it re-index the project. That should resolve the problem. It did when I had the issue.

If not, double check that the 'src' directory is configured as a source (and therefore blue in color in the project window) and the 'test' directory is configured as a test source (and therefore green in the project window). Do that in File > Project Structure.

Comment actions Permalink

Hi Mark,

Thanks for the quick reply. I started with a lot of excitement to go through your hints. Unfortunately it didn't work. I only had to invalidate the caches and restart, because project settings were already made.
The funny thing is, that when I try to reproduce this behavior on a sandbox project, it works.

Project view
My project view is showing that the package definitions are made correctly and also setting up "src" and "test" folder (blue, green) are defined.
Let's take a view of my classes:


It took a while to revalidate the cache after starting up, but it still didn't work. And the fact that it's working for my sandbox project is just showing me that it's only a matter of any configuration or project setting.
Are there any other settings which may affect this behavior?



Comment actions Permalink

Very strange indeed. I also noticed in your AmountConverterTest sceeenshot that the import static org.junit.Assert.assertEquals; statement is (incorrectly) grayed out, as if that is an unused import. Everything in your screenshots looks good. I'm afraid the only suggestion I can make is to try recreating the project from scratch. My leading theory is that something somewhere is just corrupted. It's possible there is something not configured correctly somewhere, but I simply cannot think of anything that would cause that behavior.  I usual hate giving "nuke it and start over" solution recommendations. But sometimes that is unfortunately the best strategy.  And it will likely be quicker in the long run. I wish I could be of more help. Maybe someone else has an idea (no pun intended).

Comment actions Permalink

I created project from scratch... and it worked.

Thank you, anyway... :)


Please sign in to leave a comment.