简体   繁体   English

IntelliJ IDE 中的 Junit 测试看不到测试类

[英]Junit test in IntelliJ IDE can't see class for testing

I created simple Java project in IntelliJ, one class (RandomizedQueue) and generated JUnit test class for it.我在 IntelliJ 中创建了一个简单的 Java 项目,一个类(RandomizedQueue)并为它生成了 JUnit 测试类。 So it's just two files and they both are in the same directory - src.所以它只是两个文件,它们都在同一个目录中 - src。

Everything compiled and all was well.一切都编译好了,一切都很好。 For some time.一段时间。 Then suddenly - it stopped with this error:然后突然- 它停止了这个错误:

java: cannot find symbol
  symbol:   class RandomizedQueue
  location: class RandomizedQueueTest

I tried everything I could think of.我尝试了我能想到的一切。 Recreating a project worked for a while but the same error reappeared (without any obvious reason).重新创建一个项目工作了一段时间,但同样的错误再次出现(没有任何明显的原因)。 I can't find any logic in this!我在这找不到任何逻辑! Compilation from cmd does work.从 cmd 编译确实有效。

I tried deleting everything from class and test - and I still can't make an instance in test method.我尝试从类和测试中删除所有内容 - 但我仍然无法在测试方法中创建一个实例。

here is the whole project这是整个项目

See those white x-es next to the class name?看到类名旁边的那些白色 x-es 了吗?

在此处输入图片说明

Somehow you have excluded RandomizedQueue class from the compilation.不知何故,您已从编译中排除了 RandomizedQueue 类。

在此处输入图片说明

Remove it from the excludes and everything will be back to where it was before.从排除项中删除它,一切都将恢复到以前的状态。

PS: Coursera FTW :-) PS:Coursera FTW :-)

I had the same problem.我有同样的问题。 I fixed it by rebuilding the package in which the tests were located.我通过重建测试所在的包来修复它。 Right click on the package and select "rebuild 'package name'".右键单击包并选择“重建'包名称'”。

I have the same issue every once in a while in my gradle projects (I'm on IntelliJ 2018.2.4 now).我在我的 gradle 项目中每隔一段时间都会遇到同样的问题(我现在在 IntelliJ 2018.2.4 上)。

The solution is to open a terminal and execute gradlew idea .解决方案是打开一个终端并执行gradlew idea

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM