Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 545
krm Avatar asked Nov 07 '13 19:11

krm


People also ask

How do I ignore a class in IntelliJ?

So the easiest way to exclude your test is to create a third source folder, call it /ignore, and not mark it as a source folder in IntelliJ. You can then drop any file you don't want to include in your compilation there temporarily, and drag it back to its original folder when you want to continue working on it.

How do I debug a test class in IntelliJ?

Open the test in the editor, press Ctrl+Shift+F10 or right-click on the test class and from the context menu select Run 'test name'. IntelliJ IDEA creates a run/debug configuration for the test automatically, but if you want to edit settings in your configuration, click Run | Edit Configurations on the main menu.


1 Answers

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

like image 78
Alper Akture Avatar answered Sep 25 '22 17:09

Alper Akture