Intellij “java: package org.junit does not exist”

14,185

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: enter image description here

  • Choose the first option and let the intelliJ studio add to classpath. you will get like this:

enter image description here

enter image description here

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.

Share:
14,185

Related videos on Youtube

elkshadow5
Author by

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, 2022

Comments

  • elkshadow5
    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:

    enter image description here

    I still get that error. My project directory looks like this:

    enter image description here

    Do I have to change the scope of the .jar files or the JUnit5.2 modules? My other project that JUnit is "accepted" on currently has JUnit5.0 listed in the modules page, and it shows up twice- once with the scope set to Compile and once with the scope set to Test. 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 the Compile 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
      Dilip Agheda over 5 years
      I 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
      elkshadow5 over 5 years
      github.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