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

后端 未结 13 2132
深忆病人
深忆病人 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:54

    In my case I had to:

    • close the project
    • open the build.gradle file
    • overwrite existing project? Yes
    • right click on project
      • Mark directory as > Resources Root
    0 讨论(0)
  • 2021-02-01 02:57

    Just to add a different scenario, which happened to me and some of my coworkers:

    Alt+enter in the class -> create test: IJ (2017.1.1) proposes Arquillian Junit as first option of testing library and by going with it the test class and methods are created without the 'public' identifier. Then if one decides to change the testing library to JUnit, it is easy to forget about the absence of the 'public' identifier, which causes the tests not to be recognised by IJ. Of course, the solution is to place the 'public' identifiers.

    Although this is not what happened to you it has the same consequence, therefore this answer may help others experiencing the same symptoms.

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

    I ended up manually categorising every sources root and test sources root in all the modules for the project. Worked like a charm.

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

    For some reason Intellij Idea don't recognize classes as Test class that are not explicitly public, in case class has default access specificator it will not be marked as a test. Try to change class to meet this rule. Example:

    public class TestMe {
          
     @Test
          
     public void shouldTest(){
           
         Assert.assertEquals("test", "test");
     }
    }
    
    0 讨论(0)
  • 2021-02-01 03:01

    On the latest IDE (as of Community Edition 2016.1) this option is more simplified.

    right click on the folder you want to be recognized as a source folder:

    Mark Directory As -> Sources Root

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

    OK, I fixed it.

    In menu, under File, there is an invalidate cache option. That fixed it!

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