mardi 2 mars 2021

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). 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.

I can't get JUnit to work with the sample project as well as my own projects. Whenever I add JUnit to my classpath (using Maven), it imports all the required libraries. After that, literally everything works perfectly fine except for the @Test annotation. 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.

When hovering above the @Test annotation it suggests to add JUnit4 or JUnit5 to the classpath. 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. 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". However, once again, all the other JUnit annotations work perfectly fine. Only @Test is not working and throws a "Cannot resolve symbol 'Test'" error.

I am using the following versions:

  • IntelliJ: 2020.3.2 (Ultimate Edition) [latest]
  • 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.)
  • OS: Windows 10 Home 64 bit

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. At this point I start to run out of ideas as to why everything except the @Test annotation is working perfectly fine. 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. 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. 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:

Aucun commentaire:

Enregistrer un commentaire