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)
package: com.foo.bar
class: HelloWorld.java

test (folder)
package: com.foo.bar
class: HelloWorldTest.java

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

When importing "HelloWorld.java" 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?

4 comments
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.

0
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
MBX_Project_VIEW.png
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:

AmountConverter
MBX_AmountConverter.png

AmountConverterTest
MBX_AmountConverterTest.png
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?

Sandbox

Sandbox.png

0
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).

0
Comment actions Permalink

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

Thank you, anyway... :)

0

Please sign in to leave a comment.