java.lang.Exception: No tests found matching Method using Intellij IDEA

后端 未结 12 2180
说谎
说谎 2020-12-14 14:12

I am experiencing a strange behavior of Intellij IDEA 2016.3. Having a class with method foo and a JUnit test for the method when I get java.lang.Exceptio

相关标签:
12条回答
  • 2020-12-14 14:56

    Well, after "playing" a bit with run configurations of each unit test I noticed that each Run Config has a Build goal preset in the Before Launch option (See pic below):

    After changing Build to Build Project the tests run fine.

    0 讨论(0)
  • 2020-12-14 14:57

    Since you got your answer and for others searching for solution,

    Look if your test class is extending TestCase abstract class which is a JUnit 3 related. In order to fix this you have to start your method name with "test". For example public void testFoo().

    If JUnit 3 is not the case, you're missing @Test annotation from your JUnit 4 test method.

    Note: If you're extending from TestCase and test methods are annotated with @Test and also your methods' names start with "test", then probably you're mixing JUnit 3 with JUnit 4. Don't do that. It will lead to other errors such as methods that annotated with @Ignore will not be ignored if those methods' names start with "test".

    0 讨论(0)
  • 2020-12-14 15:05

    The same issue i got with Gradle (4.5+) + new Build Cache feature

    Sometimes it's unable to find new test methods and throws exception (like you mentioned in topic)

    Solution: clean .gradle, build and out directories and try again ;)

    0 讨论(0)
  • 2020-12-14 15:08

    If you're using a theory testing framework like Junit's or Robolectric's, make sure to run the class containing the test you want, instead the test itself. Since these frameworks use the test methods as instance methods instead of static methods, any testing framework looking for a normal public static test won't find anything.

    0 讨论(0)
  • 2020-12-14 15:08

    In addition to the other answers here: the error can also happen when you forget @Test before your test method declaration. IntelliJ (2018.1) will still show you the green "Play-Button" for test execution, but that public method in your Test-Class will not be an actual test.

    0 讨论(0)
  • 2020-12-14 15:09

    In my case, I copied a test from another class and modified it, but while running the test it was still pointing to the previous one.

    Build > Clean Project solved the problem

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