2

I am experimenting what I think to be a purely Intellij related issue (though I don't know how to fix it nor where it comes from). I basically followed this tutorial to migrate tests from JUnit 4 to 5.

Tests after migration

By the end of the migration, I now have the following dependencies in pom.xml

   <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>

and the different Test Classes now uses

import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;

Problem

I keep getting Cannot resolve symbol 'jupiter' while running tests in IntelliJ. However, everything is OK in my CI pipeline ?!?!? (so probably something wrong in IntelliJ). No matter the fix actions proposed (resp. Add JUnit 5.4 to classpath and Add Maven dependencies), I keep getting the same. So what's next?

enter image description here

Environment

  • openjdk11
  • IntelliJ 2020.3.1

Interestingly, changes do not seem to be reflected on cockpit.iml, for it still contains

 <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />

and no mention of JUnit 5. Are both problems related?

What I tried

  • based on this documentation, I added org.junit.platform:junit-platform-launcher
  • I tried File | Invalidate Caches sources
  • remove .idea and cockpit.iml to reimport everything.

There is a mismatch somewhere but I can't figure where

zar3bski
  • 2,773
  • 7
  • 25
  • 58
  • I'm assuming the CI pipeline executes some commands to compile and run these tests. If you do those yourself on your machine does it work? And also verify that these tests are actually getting executed, perhaps add a failing test first. – JensV Jan 08 '21 at 10:38
  • 1
    if your using maven try to reinstall packages – Ben Davies Jan 08 '21 at 10:55
  • I checked: tests are executed in the pipeline and pass. Tests used to work in IntelliJ before the migration. Concerning `mvn test` it passes but I think that IntelliJ use a different java than the java 11 on the rest of my system – zar3bski Jan 08 '21 at 10:59
  • https://stackoverflow.com/questions/5905896/intellij-inspection-gives-cannot-resolve-symbol-but-still-compiles-code – Sibin Rasiya Jan 08 '21 at 11:03
  • @Sibin : I tried those – zar3bski Jan 08 '21 at 11:07
  • Its been awhile since I used maven, so your milage may vary, I start by refreshing the build, for gradle intellij shows a little refresh icon in the open code panes, or you can issue a refresh from the maven panel. If that fails, I would invalidate the caches, if that fails, I would force a restart. If that fails I would clear JUnit from my .m2 directory and then attempt a rebuild of the project. Sometimes if you are using something like nexus as a maven proxy it may not have download so you would need to talk to your nexus admin. – Gavin Jan 08 '21 at 12:09
  • JUnit 5.6.2 is working for me, but I am using gradle and JUnit 5 is being pulled in via a Spring Boot starter. – Gavin Jan 08 '21 at 12:10
  • Can you build the project by Maven from command line `mvn clean install`? Make sure you have your tests in **src/main/test** directory as **test** Maven scope will only attach test-scoped classes inside this directory by default. Also make sure you have **Reloaded** the Maven project in Maven tool window after you have changed the pom.xml. If problem remains can you provide a sample project? – Andrey Jan 08 '21 at 13:20

2 Answers2

0

exactly same issue. I added the Junit to Maven pom file and it fixed it.

https://mvnrepository.com/artifact/junit/junit/4.13.1

0

Turns out: a syntax error somewhere in pom.xml prevented IntelliJ from properly downloading new dependencies (or so it seems). The refresh maven deps button disappeared after clicking but libraries were not downloaded.

zar3bski
  • 2,773
  • 7
  • 25
  • 58
  • How did you find out about the syntax error? Were there any errors shown in pom.xml Editor or in Build tool window? – Andrey Jan 13 '21 at 14:37
  • It was a tricky one, for IntelliJ pointed the error on the `` while, in fact, the problem was that I introduced `${version}` in `` – zar3bski Jan 13 '21 at 15:24
  • Thanks for the information. We will try to make this error more prominent: https://youtrack.jetbrains.com/issue/IDEA-258602 – Andrey Jan 18 '21 at 15:10