Intellij “java: package org.junit does not exist”
Thanks for uploading to github.
I imported your project to IntelliJ and hit build. I also got around 10 errors complaining about jUnit.
Solution: - Go to the import statements for which you get error message that no package jar file is available. put cursor there and press ALT+ENTER. You will get options like this:
- Choose the first option and let the intelliJ studio add to classpath. you will get like this:
After that build was successful and all the errors were gone. Also, I learnt that if you add each package manually then chances of errors will be high. best thing is to use maven package management, give it the package you want and then it will figure out all the dependancies that comes with it and download to your project. Also, this has nothing to do with jUnit version. Any decent recent version will do. Hope this helps.
Related videos on Youtube
elkshadow5
Graduate Computer Science/Software Engineering student Have experience in Python, Java, Bash, C, LaTeX, HTML, FORTRAN, BASIC, MATLAB, Excel, JavaScript, PostgreSQL, Batch, Racket, and C++
Updated on June 04, 2022Comments
-
elkshadow5 almost 2 years
FULL DISCLOSURE: I know this question has been asked before, but no previous answers actually solved my problem. Do not mark as duplicate please the answer in this question does not actually solve my problem.
I currently have 3 separate projects that use IntelliJ, one each for 3 different university courses. On one of them, JUnit testing works just fine without any issues. On the second project I haven't had to do any JUnit testing so I don't know whether or not it works on there. On a new project I created, it doesn't work at all and gives me about 50 errors all along the lines of
java: package org.junit does not exist
.I saw this question and followed the steps in the accepted answer to try and fix the problem. My project dependencies now looks like this:
I still get that error. My project directory looks like this:
Do I have to change the scope of the
.jar
files or theJUnit5.2
modules? My other project that JUnit is "accepted" on currently hasJUnit5.0
listed in the modules page, and it shows up twice- once with the scope set toCompile
and once with the scope set toTest
. Is there a huge difference between JUnit5.0 and JUnit5.2 and how they work? Do I have to add JUnit5.2 again but with theCompile
scope? If so, how?This question doesn't work either since it has to do with Android development and from what I can tell they have their project(s) set up completely different from me.
-
Dilip Agheda over 5 yearsI am happy to help you. In order to really understand the unique situation you are facing, are you able to share your code on github so that i can recreate the problem and suggest possible solutions?
-
elkshadow5 over 5 yearsgithub.com/elkshadow5/stackoverflowtest I don't know if the problem is in my code though, since I implemented in code exactly how I did in my other project yet that one has no errors
-