IntelliJ - 如何从“运行”中的失败单元测试跳转到源而不是编译类。视图 [英] IntelliJ - How to jump to source instead of compiled classes from failed unit tests in the "Run" view

查看:106
本文介绍了IntelliJ - 如何从“运行”中的失败单元测试跳转到源而不是编译类。视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在IntelliJ中运行JUnit测试并且其中一个测试失败时,我想通过双击它来跳转到失败测试的源代码(或者右击它并选择Jump to source或在结果视图中显示显示源(在运行视图中的失败测试列表中)。但是,此功能并不总是正常工作。有时会显示源代码,有时在编辑器窗口中只显示测试的已编译.class文件。
双击失败的测试后,我总是希望在编辑器窗口中看到源代码(.java文件)而不是.class文件。
一个解决方案是在编辑器窗口中单击Attach Sources ...,其中显示测试类的.class文件。但是,我必须为每个测试文件执行此操作,并且每次测试都需要花费很多时间重复执行。在我看来,IntelliJ应该自动找到源代码,因为它存在于我的Project中(它是我自己的类,它的源代码在项目中,我从Project视图运行这个测试,其中带有源代码的类是可见的)。如何配置IntelliJ,以便它为我运行的每个单元测试自动找到源代码?

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?

显示的.class文件而不是.java文件包含在由Maven构建的jar文件中。

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

推荐答案

您应该可以在项目视图(文件>项目结构)中转到外部库,找到那个jar包含.class文件,然后右键单击(或F4)。您将看到打开库设置。在该对话框中,您可以将src文件夹附加到库中。

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.

这篇关于IntelliJ - 如何从“运行”中的失败单元测试跳转到源而不是编译类。视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆