IntelliJ - How to jump to source instead of compiled classes from failed unit tests in the "Run" view

26,345

Solution 1

You should be able to go to the External Libraries in your Project view (File > Project Structure), find the jar that contains the .class file, and right click (or F4). You will see Open Library Settings. From that dialog, you can attach a src folder to the library. enter image description here

Solution 2

I had a similar issue. In my case it was due to incorrect Module configuration. Basically you must ensure that the source folder containing the java files is added to Sources tab in corresponding module.

To do this Go to Project Structure (Ctrl + Alt + Shift + S) and select Modules. Choose corresponding module and verify that the source folder containing the java files is correctly added to the Sources Folders. If it is not then add it.

Solution 3

I got this issue today. The solution for me was to right click on main pom.xml, then maven, then reimport.

Solution 4

I'm using IntelliJ IDEA 2019.3 ultimate edition and faced this issue, debugger would jump to decompiled .class files On the top right corner once your debugger jumps to .class file enter image description here

you will see an option to 'choose sources', choose the directory which has your .java file. Worked for me atleast.

Solution 5

I Had a similar issue. The issue was still there even after pointing to the correct source folder but I got rid of it by setting the classes folder to the source code's root folder.

enter image description here

Share:
26,345
krm
Author by

krm

Updated on February 17, 2021

Comments

  • krm
    krm about 3 years

    When I run my JUnit tests in IntelliJ and one of them fails, I would like to jump to the source code of the failing test by double-clicking it (or by right-clicking it and selecting "Jump to source" or "Show source") in the results view (in the list of failed tests in the "Run" view). However, this feature doesn't always work correctly. Sometimes the source code is shown and sometimes only the compiled ".class" file of the test is shown to me in the editor window. I would always like to see the source code (".java" file) instead of the ".class" file in the editor window after double-clicking the failed test. One solution for it is to click "Attach Sources..." in the editor window, where the ".class" file of the test class is displayed. However, I have to do it for every test file and it takes much time to do it repeatedly for every test. In my opinion IntelliJ should find the source code automatically, because it's present in my Project (it's my own class and its source code is in the project and I run this test from the Project view, where the classes with source code are visible). How can I configure IntelliJ, so that it finds the source code automatically for every unit test which I run?

    The ".class" files which are shown instead of the ".java" files are contained in a jar file which is built by Maven.

  • Alper Akture
    Alper Akture over 10 years
    And if your module containing the class file is in the intellij project, it may also be possible that the pom version declared for the module in your parent pom, references an older version of the project.
  • krm
    krm over 10 years
    As I mentioned in the description of my question, I know this solution (in a slightly different way, because the "Attach Sources..." appears in the upper right corner of the editor window, but it's the same mechanism) and as I've also written in the description, I would expect IntelliJ to be more "intelligent" and to discover the java source files which are contained in my project, which are compiled to the class files. The ".java" and ".class" files which I mean aren't files of external libraries, but they are files written by me in the same project in IntelliJ.
  • emulcahy
    emulcahy almost 10 years
    Thanks, this was very helpful to me!
  • Jeff
    Jeff over 7 years
    This solved the problem for me. The only annoying side effect now is that the source code's root folder is highlighted Yellow in the project navigation view.