Reputation: 73
Hi, I am having trouble create Junit Test Case with Eclipse. I've google this error, but all the posts tell me that you have to add. As shown below I had.
The error is The import org cannnot be resloved
Somebody know what are the possibilities of my problems ?
Upvotes: 1
Views: 934
Reputation: 73
With @nitind help, I could solve the problem.
Because I did not know what is module path and google it. I ended up reading this post and in that post it says
There is one special case: If you have a module-info.java in your project and have test code in your project, you usually don't want to mention test dependencies like junit in the module-info.java. There are two solutions for this:
Create a dedicated test module. This has always been the convention for osgi-based projects. Disadvantage is that you can only use public api in your tests
The solution used by maven: Put your test dependencies on the classpath. When compiling test code, maven adds command line options that allow the code in the named module to read the unnamed module (which is not possible via the module-info.java).
So, as it says I made dedicated test module like the picture below.
Build Path > Configure Build Path
Contains test sources: No
to YesAllow output folders for source folders
test
(or anywhere you want other than you default (bin))Run the test and the test should work from now.
Upvotes: 2