Why does Intellij IDEA suddenly not recognize tests in test folder anymore?

后端 未结 13 2131
深忆病人
深忆病人 2021-02-01 02:26

I\'m using JUnit since I started this project and everything works just fine. I have a couple of hundreds tests, and of course, here and there I start them all. Right click on r

相关标签:
13条回答
  • 2021-02-01 02:40

    A poor workaround for this is to let IntelliJ run tests instead of Gradle.

    File > Settings > Build Tools > Gradle > Run Tests With > IntelliJ Test Runner

    This is a similar issue with another test framework on Gradle. https://youtrack.jetbrains.com/issue/IDEA-221159

    0 讨论(0)
  • 2021-02-01 02:41

    If you are using IntelliJ for test execution and debugging, but not for editing. Your other editor/IDE may be battling with IntelliJ for control over generated files (*.class) -- resulting in IntelliJ reporting that No tests were found (and maybe spurious build errors too).

    In my case, Visual Studio Code seem to be having this effect (after recent updates to both tools).

    The solution that I have found is to close Visual Studio Code and then clean rebuild the project with IntelliJ or from the command-line. In otherwords, my dual-IDE workflow no longer works -- so I have to edit in IntelliJ.

    0 讨论(0)
  • 2021-02-01 02:42

    Fixed this a few times by... open file --> project structure. There, look on the left side menu as last entry there is "problem" count(if more then zero). click on those and then for for each problem highlighted in red in intellij in modules/libraries, remove them (minus button). They will be given module names like "test1..23" since intellij cant make out the structure. After deleting all marked red, close + restart intellij. Dont run maven refresh at this stage, since it will reintroduce the same error again. By restarting intellij will trigger a new scan of the project structure again.

    0 讨论(0)
  • 2021-02-01 02:43

    In my case, we are moving from JUnit 4 to JUnit 5 and I mixed the @Test of them.

    In short:

    • if you use @RunWith() of JUnit 4, you must use @org.junit.Test to annotate test methods.
    • if you use @ExtendWith() of JUnit 5, you must use @org.junit.jupiter.api.Test instead.

    When I change the import, my class can be run as test class again.

    0 讨论(0)
  • 2021-02-01 02:43

    Have a try changing a JUnit dependency version. One release forward or backwards. It can help invalidate test cache.

    If you use a dependency management tool such as Maven or Gradle, go to the .pom or .gradle file and change the version of the JUnit library.

    For instance change 4.11 to 4.12 or 4.10 in the version section:

    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <!-- change here -->
          <version>4.11</version>
          <scope>test</scope>
       </dependency>
    </dependencies>
    
    0 讨论(0)
  • 2021-02-01 02:52

    None of the previous answers worked for me in IDEA 2019.1.2 (or -.3) with Junit Jupiter 5.5.0. I had git-cloned a couple of projects that I had pushed to GitHub from a different computer, where their tests ran fine. On my new laptop, I got "No tests were found" no matter how I tried to run them.

    What finally did work: I deleted the IDEA-generated test.iml file, because I had noticed there was no such file in a virgin project I had created just to see if I could run tests at all (I could indeed). After I deleted this file in both older projects, tests ran perfectly. No new test.iml was generated.

    I don't know how or when those files got generated. Because the git repos are private, I didn't bother to gitignore IDEA's *.*ml files; nevertheless, they weren't in the GitHub repos. Furthermore, they were at the roots of the projects, not in the .idea directory.

    0 讨论(0)
提交回复
热议问题