Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.Exception: No tests found matching Method foo when running the test. After I do mvn test it succeeds and then running the unit test right after executing mvn command it suddenly runs green. Seems like IDEA does not compile automatically. How can I fix this?

P.S. No settings were altered after upgrading to v. 2016.3

like image 897
Arthur Eirich Avatar asked Nov 29 '16 10:11

Arthur Eirich


2 Answers

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.

like image 55
user70585 Avatar answered Sep 17 '22 13:09

user70585


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

like image 21
Evgeny Lebedev Avatar answered Sep 21 '22 13:09

Evgeny Lebedev