java 运行单元测试右键单击上下文项在 IntelliJ 12 中不可见

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13779537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 13:56:58  来源:igfitidea点击:

Running unit tests right click context item not visible with IntelliJ 12

javajunitintellij-idea

提问by Blankman

I downloaded the latest intellij 12 release, and now I don't see that right click context menu item to run my unit test for the current file.

我下载了最新的 intellij 12 版本,现在我没有看到右键单击上下文菜单项来运行当前文件的单元测试。

Where is that option now?

现在那个选项在哪里?

采纳答案by Blankman

For some reason my project settings seemed to have not been picked up correctly with IntelliJ 12, I had to reset the /test folder as a test source and it works fine now.

出于某种原因,我的项目设置似乎没有被 IntelliJ 12 正确选择,我不得不将 /test 文件夹重置为测试源,现在它可以正常工作了。

回答by Kermit_ice_tea

The solution which worked for me, is as follows...

对我有用的解决方案如下...

Right click on the test folder------>Mark Directory AS------>select Test Source

右键单击测试文件夹------>标记目录AS------>选择测试源

回答by MattCurtis

Just had the same issue in a maven project - I had forgotten to mark the test class as public which resolved it immediately.

刚刚在 Maven 项目中遇到了同样的问题 - 我忘记将测试类标记为 public 并立即解决了它。

回答by Hejwo

I also had this problem under IDEA 14.1.4 but JUnit plugin was on. After some time spent on comparing my old {HOME}/.IdeaIC14folder and newly created one, I've discovered that problem lies in AntDebugger v1.2.0 plugin. Uninstalling it helped.

我在 IDEA 14.1.4 下也遇到了这个问题,但是 JUnit 插件是打开的。花了一些时间比较旧的{HOME}/.IdeaIC14文件夹和新创建的文件夹后,我发现问题出在 AntDebugger v1.2.0 插件中。卸载它有帮助。

So if anyone still have problems with run item in context menu maybe it's because of some underdeveloped plugin.

因此,如果有人仍然在上下文菜单中遇到运行项目的问题,那可能是因为一些未开发的插件。

回答by Joshua

Try to add junit plugin. Preferences -> plugins -> junit.add junit plugin

尝试添加junit插件。首选项 -> 插件 -> junit。添加junit插件

回答by Kre?imir Nesek

Test sources were marked correctly in my case. File -> Invalidate Caches -> Restart did it for me.

在我的情况下,测试源被正确标记。File -> Invalidate Caches -> Restart 为我做了。

回答by Hamed

What solved it for me was to put the test files inside a separate directory. Moreover, the test directory should be located OUTSIDE the src directory. Then, I had the right click menu item to mark the directory as test. Finally, I had to make both the test method and class containing it 'public' and also the method had to be 'public void'.

为我解决的是将测试文件放在一个单独的目录中。此外,测试目录应位于 src 目录之外。然后,我有右键单击菜单项将目录标记为测试。最后,我必须使测试方法和包含它的类都为“公共”,并且该方法必须为“公共无效”。

I have no idea where are all these restrictions documented. I am new to Java and JUnit, anyway.

我不知道所有这些限制记录在哪里。无论如何,我是 Java 和 JUnit 的新手。

回答by dSebastien

In my case, the issue occurred because of the Node plugin; disabling it fixed the issue; after a restart of IntelliJ, my Run options were back.

就我而言,问题是由 Node 插件引起的;禁用它可以解决问题;重新启动 IntelliJ 后,我的运行选项又回来了。

I could identify the issue by looking at IntelliJ's logs, where there were NoSuchMethod errors when I right clicked on a test class/method name.

我可以通过查看 IntelliJ 的日志来识别问题,当我右键单击测试类/方法名称时,其中存在 NoSuchMethod 错误。

回答by powder366

I reinstalled IntelliJ on mac and it worked again.

我在 mac 上重新安装了 IntelliJ,它又工作了。

回答by Jon Onstott

I had this issue in IDEA 14.1.4. Somehow, my JUnit plugin became disabled in Settings --> Plugins. I re-enabled it and am back in business.

我在 IDEA 14.1.4 中遇到过这个问题。不知何故,我的 JUnit 插件在设置 --> 插件中被禁用。我重新启用它并重新开始营业。