简体   繁体   English

JUnit - 除@Test 注释外,每个注释都有效

[英]JUnit - Every annotation works except the @Test annotation

I've cloned the sample project which JetBrains uses for demonstration purposes ( https://github.com/JetBrains/intellij-samples.git ) from GitHub since I had an issue with JUnit and wanted to see whether those issues persist when using an official project (to make sure that I haven't messed something up). I've cloned the sample project which JetBrains uses for demonstration purposes ( https://github.com/JetBrains/intellij-samples.git ) from GitHub since I had an issue with JUnit and wanted to see whether those issues persist when using an官方项目(以确保我没有搞砸)。 Unfortunately the issue persists and after hours of research on Google, StackOverflow or last but not least the JetBrains Support Board I can't manage to get this issue resolved.不幸的是,问题仍然存在,经过数小时对 Google、StackOverflow 或最后但并非最不重要的 JetBrains 支持委员会的研究,我无法解决这个问题。

I can't get JUnit to work with the sample project as well as my own projects.我无法让 JUnit 与示例项目以及我自己的项目一起使用。 Whenever I add JUnit to my classpath (using Maven), it imports all the required libraries.每当我将 JUnit 添加到我的类路径(使用 Maven)时,它都会导入所有必需的库。 After that, literally everything works perfectly fine except for the @Test annotation.在那之后,除了@Test 注释之外,几乎所有东西都可以正常工作。 I can use other annotations like org.junit.jupiter.api.Disabled (@Disabled) or org.junit.jupiter.api.ParameterizedTest (@ParameterizedTest) but whenever I try to use the org.junit.jupiter.api.Test (@Test) annotation I get a "Cannot resolve symbol 'Test'" error. I can use other annotations like org.junit.jupiter.api.Disabled (@Disabled) or org.junit.jupiter.api.ParameterizedTest (@ParameterizedTest) but whenever I try to use the org.junit.jupiter.api.Test ( @Test) 注释我收到“无法解析符号'Test'”错误。

When hovering above the @Test annotation it suggests to add JUnit4 or JUnit5 to the classpath.当悬停在 @Test 注释上方时,它建议将 JUnit4 或 JUnit5 添加到类路径中。 If I select that option I still get the same error and when hovering above the @Test annotation afterwards it still suggests the same thing.如果我 select 那个选项我仍然得到同样的错误,当悬停在 @Test 注释上方时,它仍然暗示同样的事情。 I've already tried to do "Maven > Reload Project", "File > Invalidate Caches / Restart", reinstalling IntelliJ Ultimate and importing the JUnit API manually by adding it as an external Java library to the project without using Maven or Gradle. I've already tried to do "Maven > Reload Project", "File > Invalidate Caches / Restart", reinstalling IntelliJ Ultimate and importing the JUnit API manually by adding it as an external Java library to the project without using Maven or Gradle. I also made sure that the directory in which I am trying to use the @Test annotation in is a "Test Source Folder".我还确保我尝试在其中使用 @Test 注释的目录是“测试源文件夹”。 However, once again, all the other JUnit annotations work perfectly fine.但是,再一次,所有其他 JUnit 注释都可以正常工作。 Only @Test is not working and throws a "Cannot resolve symbol 'Test'" error.只有@Test 不起作用并引发“无法解析符号'Test'”错误。

I am using the following versions:我正在使用以下版本:

  • IntelliJ: 2020.3.2 (Ultimate Edition) [latest] IntelliJ:2020.3.2(终极版)[最新]
  • Java: 1.8 "1.8.0_144" Java:1.8“1.8.0_144”
  • JUnit: 5.7.1 (But I've also tried to use plenty of other versions [from 4.0 to 5.8] instead without success.) JUnit:5.7.1(但我也尝试使用许多其他版本 [从 4.0 到 5.8],但没有成功。)
  • OS: Windows 10 Home 64 bit操作系统:Windows 10 家庭 64 位

I've tried setting up JUnit with Eclipse using Maven and it immediately worked so I am not sure whether this has something to do with IntelliJ specifically.我尝试使用 Maven 设置 JUnit 和 Eclipse 并且它立即起作用所以我不确定这是否与 IntelliJ 有关。 At this point I start to run out of ideas as to why everything except the @Test annotation is working perfectly fine.在这一点上,我开始不知道为什么除了 @Test 注释之外的所有东西都可以正常工作。 I've already tried plenty of suggestions from aforementioned sites, hence I really hope that we can get this issue resolved here.我已经尝试了上述网站的大量建议,因此我真的希望我们可以在这里解决这个问题。

I've appended a screenshot of one of the classes where this issue occurs.我已经附加了出现此问题的类之一的屏幕截图。 All of the code as well as the pom.xml file / etc is the same as in https://github.com/JetBrains/intellij-samples .所有代码以及 pom.xml 文件 / 等都与https://github.com/JetBrains/intellij-samples中的相同。 I haven't modified any of the files locally and only tried "Maven > Reload Project" as well as "File > Invalidate Caches / Restart" with the sample project.我没有在本地修改任何文件,只在示例项目中尝试了“Maven > Reload Project”以及“File > Invalidate Caches / Restart”。 If you need any further info in order to have a look at this issue make sure to let me know.如果您需要任何进一步的信息以查看此问题,请务必让我知道。

Thanks in advance.提前致谢。

Max最大限度

Attachments:附件:

Please see if deleting the system directory helps while the IDE is not running.请查看在 IDE 未运行时删除系统目录是否有帮助。 It looks like file system cache related issue.它看起来像文件系统缓存相关的问题。 Should be fixed in 2021.1 release. 在 2021.1 版本中修复。

The issue is not reproducible in 2020.3.2 with the clean system directory:使用干净的系统目录在 2020.3.2 中无法重现该问题:

测试

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

相关问题 @Test注释不工作junit 4 - @Test annotation not working junit 4 在删除'junit-platform-surefire-provider'后,在Junit5中通过@Tag注释执行测试将无法进行 - Executing test by @Tag annotation in Junit5 will not work after removing 'junit-platform-surefire-provider' 使用 Maven 使用注释 @Tag("name_test") 过滤 JUnit 5 测试用例 - Filter JUnit 5 test cases with the annotation @Tag("name_test") using Maven Intellij无法识别测试注释 - Intellij not recognizing test annotation 测试不是注解类型 - Test is not an annotation type Maven测试和例外测试注释 - Maven test and excepted test annotation 将自定义批注挂钩到Maven中的JUnit Tester - Hook custom annotation to the JUnit Tester in Maven NoClassDefFoundError:注释处理期间的org / junit / AfterClass - NoClassDefFoundError: org/junit/AfterClass during annotation processing 如何在 maven-surefire-plugin XML 报告中为 junit 中的 @RepeatedTest 注释测试用例获取正确的重复值和 package 名称 - How to get the correct repetition value and package name in maven-surefire-plugin XML report for @RepeatedTest annotation test cases in junit 如何使用@Suite 注释运行 JUnit5 套件 - How to run JUnit5 suite using the @Suite annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM